From cc6899d4160082b859266181924a628e0da1379e Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Mon, 1 Feb 2021 23:50:40 +0300 Subject: [PATCH] refac(core): impl from path trait for builder --- migra-core/src/path.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/migra-core/src/path.rs b/migra-core/src/path.rs index cc8ae73..f05be98 100644 --- a/migra-core/src/path.rs +++ b/migra-core/src/path.rs @@ -6,12 +6,20 @@ pub struct PathBuilder { buf: PathBuf, } -impl PathBuilder { - pub fn new>(path: P) -> Self { +impl> From

for PathBuilder { + fn from(path: P) -> Self { PathBuilder { buf: path.as_ref().to_path_buf(), } } +} + +impl PathBuilder { + pub fn new>() -> Self { + PathBuilder { + buf: PathBuf::new(), + } + } pub fn append>(&mut self, path: P) -> &mut Self { self.buf.push(path); @@ -37,21 +45,21 @@ mod tests { #[test] fn create_path_builder() { - let path = PathBuilder::new("test").build(); + let path = PathBuilder::from("test").build(); assert_eq!(path, Path::new("test")) } #[test] fn append_path_to_builder() { - let path = PathBuilder::new("directory").append("schema.sql").build(); + let path = PathBuilder::from("directory").append("schema.sql").build(); assert_eq!(path, Path::new("directory/schema.sql")) } #[test] fn add_default_extension_for_path() { - let path = PathBuilder::new("directory") + let path = PathBuilder::from("directory") .append("schema") .default_extension("sql") .build();