From d511c98e4770228fcd758ff0b528a701e0161a8a Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 15 Dec 2024 17:55:23 +0000 Subject: [PATCH] refactor: replace Ctx::new with Ctx::From --- src/lib.rs | 4 ++-- src/main.rs | 2 +- src/tests/mod.rs | 12 ++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8aec10c..1d2600c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,8 +67,8 @@ pub struct Ctx { pub net: Net, pub prt: Printer, } -impl Ctx { - pub fn new(base: impl Into) -> Self { +impl From for Ctx { + fn from(base: PathBuf) -> Self { Self { fs: kxio::fs::new(base), net: kxio::net::new(), diff --git a/src/main.rs b/src/main.rs index 7b8210e..e28dab2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,5 +6,5 @@ use trello_to_deck::{run, Ctx}; #[tokio::main] #[cfg_attr(test, mutants::skip)] async fn main() -> Result<()> { - run(Ctx::new(std::env::current_dir()?)).await + run(Ctx::from(std::env::current_dir()?)).await } diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 6d1fc62..7723736 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -15,3 +15,15 @@ mod config; pub(crate) mod given; mod init; mod template; + +#[test] +fn ctx_from_pathbuf() { + //given + let pathbuf = std::path::PathBuf::from("test"); + + //when + let ctx = Ctx::from(pathbuf.clone()); + + //then + assert_peq!(ctx.fs.base(), pathbuf); +}