Skip to content

Commit 3d9fec6

Browse files
committed
pth : TryFrom< String > for AbsolutePath
1 parent 815e41e commit 3d9fec6

File tree

8 files changed

+143
-20
lines changed

8 files changed

+143
-20
lines changed

Cargo.toml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ default-features = false
101101
version = "~0.27.0"
102102
path = "module/core/interval_adapter"
103103
default-features = false
104-
features = [ "enabled" ]
104+
# features = [ "enabled" ]
105105

106106
[workspace.dependencies.winterval]
107107
version = "~0.3.0"
108108
path = "module/alias/winterval"
109109
default-features = false
110-
features = [ "enabled" ]
110+
# features = [ "enabled" ]
111111

112112
[workspace.dependencies.collection_tools]
113113
version = "~0.15.0"
@@ -121,31 +121,31 @@ default-features = false
121121
version = "~0.32.0"
122122
path = "module/core/derive_tools"
123123
default-features = false
124-
features = [ "enabled" ]
124+
# features = [ "enabled" ]
125125

126126
[workspace.dependencies.derive_tools_meta]
127127
version = "~0.31.0"
128128
path = "module/core/derive_tools_meta"
129129
default-features = false
130-
features = [ "enabled" ]
130+
# features = [ "enabled" ]
131131

132132
[workspace.dependencies.reflect_tools]
133133
version = "~0.3.0"
134134
path = "module/core/reflect_tools"
135135
default-features = false
136-
features = [ "enabled" ]
136+
# features = [ "enabled" ]
137137

138138
[workspace.dependencies.reflect_tools_meta]
139139
version = "~0.3.0"
140140
path = "module/core/reflect_tools_meta"
141141
default-features = false
142-
features = [ "enabled" ]
142+
# features = [ "enabled" ]
143143

144144
[workspace.dependencies.format_tools]
145145
version = "~0.2.0"
146146
path = "module/core/format_tools"
147147
default-features = false
148-
features = [ "enabled" ]
148+
# features = [ "enabled" ]
149149
# xxx : remove features, maybe
150150

151151
# [workspace.dependencies.type_constructor]
@@ -162,24 +162,24 @@ default-features = false
162162
version = "~0.27.0"
163163
path = "module/core/variadic_from"
164164
default-features = false
165-
features = [ "enabled" ]
165+
# features = [ "enabled" ]
166166

167167
[workspace.dependencies.clone_dyn]
168-
version = "~0.28.0"
168+
version = "~0.29.0"
169169
path = "module/core/clone_dyn"
170170
default-features = false
171-
features = [ "enabled" ]
171+
# features = [ "enabled" ]
172172

173173
[workspace.dependencies.clone_dyn_meta]
174174
version = "~0.27.0"
175175
path = "module/core/clone_dyn_meta"
176-
features = [ "enabled" ]
176+
# features = [ "enabled" ]
177177

178178
[workspace.dependencies.clone_dyn_types]
179179
version = "~0.26.0"
180180
path = "module/core/clone_dyn_types"
181181
default-features = false
182-
features = [ "enabled" ]
182+
# features = [ "enabled" ]
183183

184184

185185
## mem
@@ -367,7 +367,7 @@ path = "module/alias/file_tools"
367367
default-features = false
368368

369369
[workspace.dependencies.pth]
370-
version = "~0.18.0"
370+
version = "~0.19.0"
371371
path = "module/core/pth"
372372
default-features = false
373373

module/core/clone_dyn/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clone_dyn"
3-
version = "0.28.0"
3+
version = "0.29.0"
44
edition = "2021"
55
authors = [
66
"Kostiantyn Wandalen <[email protected]>",
@@ -36,6 +36,7 @@ derive_clone_dyn = [ "dep:clone_dyn_meta", "clone_dyn_meta/enabled", "clone_dyn_
3636
[dependencies]
3737
clone_dyn_meta = { workspace = true, optional = true }
3838
clone_dyn_types = { workspace = true, optional = true }
39+
# clone_dyn_types = { version = "0.27.0", optional = true }
3940

4041
[dev-dependencies]
4142
test_tools = { workspace = true }

module/core/pth/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pth"
3-
version = "0.18.0"
3+
version = "0.19.0"
44
edition = "2021"
55
authors = [
66
"Kostiantyn Wandalen <[email protected]>",

module/core/pth/src/path/absolute_path.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ mod private
131131
#[ inline ]
132132
fn try_from( src : PathBuf ) -> Result< Self, Self::Error >
133133
{
134-
<Self as TryFrom< &Path >>::try_from( &src.as_path() )
134+
< Self as TryFrom< &Path > >::try_from( &src.as_path() )
135135
}
136136
}
137137

@@ -142,7 +142,7 @@ mod private
142142
#[ inline ]
143143
fn try_from( src : &PathBuf ) -> Result< Self, Self::Error >
144144
{
145-
<Self as TryFrom< &Path >>::try_from( &src.as_path() )
145+
< Self as TryFrom< &Path > >::try_from( &src.as_path() )
146146
}
147147
}
148148

@@ -164,14 +164,36 @@ mod private
164164
}
165165
}
166166

167-
impl<'a> TryFrom< &'a str > for AbsolutePath
167+
impl< 'a > TryFrom< &'a str > for AbsolutePath
168168
{
169169
type Error = std::io::Error;
170170

171171
#[ inline ]
172172
fn try_from( src : &'a str ) -> Result< Self, Self::Error >
173173
{
174-
<Self as TryFrom< &Path >>::try_from( src.as_ref() )
174+
< Self as TryFrom< &Path > >::try_from( src.as_ref() )
175+
}
176+
}
177+
178+
impl< 'a > TryFrom< &'a String > for AbsolutePath
179+
{
180+
type Error = std::io::Error;
181+
182+
#[ inline ]
183+
fn try_from( src : &'a String ) -> Result< Self, Self::Error >
184+
{
185+
< Self as TryFrom< &Path > >::try_from( src.as_ref() )
186+
}
187+
}
188+
189+
impl< 'a > TryFrom< String > for AbsolutePath
190+
{
191+
type Error = std::io::Error;
192+
193+
#[ inline ]
194+
fn try_from( src : String ) -> Result< Self, Self::Error >
195+
{
196+
< Self as TryFrom< &Path > >::try_from( src.as_ref() )
175197
}
176198
}
177199

@@ -220,7 +242,7 @@ mod private
220242
}
221243
}
222244

223-
impl<'a> TryFrom< &'a AbsolutePath > for &'a str
245+
impl< 'a > TryFrom< &'a AbsolutePath > for &'a str
224246
{
225247
type Error = std::io::Error;
226248

module/core/pth/src/path/canonical_path.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@ mod private
115115
}
116116
}
117117

118+
impl< 'a > TryFrom< &'a String > for CanonicalPath
119+
{
120+
type Error = std::io::Error;
121+
122+
#[ inline ]
123+
fn try_from( src : &'a String ) -> Result< Self, Self::Error >
124+
{
125+
< Self as TryFrom< &Path > >::try_from( src.as_ref() )
126+
}
127+
}
128+
129+
impl< 'a > TryFrom< String > for CanonicalPath
130+
{
131+
type Error = std::io::Error;
132+
133+
#[ inline ]
134+
fn try_from( src : String ) -> Result< Self, Self::Error >
135+
{
136+
< Self as TryFrom< &Path > >::try_from( src.as_ref() )
137+
}
138+
}
139+
118140
impl TryFrom< PathBuf > for CanonicalPath
119141
{
120142
type Error = std::io::Error;

module/core/pth/src/path/native_path.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,28 @@ mod private
114114
}
115115
}
116116

117+
impl< 'a > TryFrom< &'a String > for NativePath
118+
{
119+
type Error = std::io::Error;
120+
121+
#[ inline ]
122+
fn try_from( src : &'a String ) -> Result< Self, Self::Error >
123+
{
124+
< Self as TryFrom< &Path > >::try_from( src.as_ref() )
125+
}
126+
}
127+
128+
impl< 'a > TryFrom< String > for NativePath
129+
{
130+
type Error = std::io::Error;
131+
132+
#[ inline ]
133+
fn try_from( src : String ) -> Result< Self, Self::Error >
134+
{
135+
< Self as TryFrom< &Path > >::try_from( src.as_ref() )
136+
}
137+
}
138+
117139
impl TryFrom< PathBuf > for NativePath
118140
{
119141
type Error = std::io::Error;

module/core/pth/tests/inc/absolute_path_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ use super::*;
22

33
mod basic_test;
44
mod from_paths_test;
5+
mod try_from_test;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use super::*;
2+
use std::convert::TryFrom;
3+
4+
#[ test ]
5+
fn try_from_absolute_path_test()
6+
{
7+
use std::path::{ Path, PathBuf };
8+
use the_module::AbsolutePath;
9+
10+
// Create an AbsolutePath instance
11+
let absolute_path = AbsolutePath::try_from( "/absolute/path" ).unwrap();
12+
13+
// Test conversion to &str
14+
let path_str : &str = TryFrom::try_from( &absolute_path ).unwrap();
15+
println!( "&str from AbsolutePath: {:?}", path_str );
16+
assert_eq!( path_str, "/absolute/path" );
17+
18+
// Test conversion to String
19+
let path_string : String = TryFrom::try_from( &absolute_path ).unwrap();
20+
println!( "String from AbsolutePath: {:?}", path_string );
21+
assert_eq!( path_string, "/absolute/path" );
22+
23+
// Test conversion to PathBuf
24+
let path_buf : PathBuf = TryFrom::try_from( absolute_path.clone() ).unwrap();
25+
println!( "PathBuf from AbsolutePath: {:?}", path_buf );
26+
assert_eq!( path_buf, PathBuf::from( "/absolute/path" ) );
27+
28+
// Test conversion to &Path
29+
let path_ref : &Path = absolute_path.as_ref();
30+
println!( "&Path from AbsolutePath: {:?}", path_ref );
31+
assert_eq!( path_ref, Path::new( "/absolute/path" ) );
32+
33+
// Test conversion from &String
34+
let string_path : String = String::from( "/absolute/path" );
35+
let absolute_path_from_string : AbsolutePath = TryFrom::try_from( &string_path ).unwrap();
36+
println!( "AbsolutePath from &String: {:?}", absolute_path_from_string );
37+
assert_eq!( absolute_path_from_string, absolute_path );
38+
39+
// Test conversion from String
40+
let absolute_path_from_owned_string : AbsolutePath = TryFrom::try_from( string_path.clone() ).unwrap();
41+
println!( "AbsolutePath from String: {:?}", absolute_path_from_owned_string );
42+
assert_eq!( absolute_path_from_owned_string, absolute_path );
43+
44+
// Test conversion from &Path
45+
let path_ref : &Path = Path::new( "/absolute/path" );
46+
let absolute_path_from_path_ref : AbsolutePath = TryFrom::try_from( path_ref ).unwrap();
47+
println!( "AbsolutePath from &Path: {:?}", absolute_path_from_path_ref );
48+
assert_eq!( absolute_path_from_path_ref, absolute_path );
49+
50+
// Test conversion from PathBuf
51+
let path_buf_instance : PathBuf = PathBuf::from( "/absolute/path" );
52+
let absolute_path_from_path_buf : AbsolutePath = TryFrom::try_from( path_buf_instance.clone() ).unwrap();
53+
println!( "AbsolutePath from PathBuf: {:?}", absolute_path_from_path_buf );
54+
assert_eq!( absolute_path_from_path_buf, absolute_path );
55+
}

0 commit comments

Comments
 (0)