File tree Expand file tree Collapse file tree 4 files changed +38
-3
lines changed Expand file tree Collapse file tree 4 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -128,6 +128,16 @@ impl From<&'_ &'static str> for OsStr {
128128 }
129129}
130130
131+ #[ cfg( feature = "string" ) ]
132+ impl From < Cow < ' static , str > > for OsStr {
133+ fn from ( cow : Cow < ' static , str > ) -> Self {
134+ match cow {
135+ Cow :: Borrowed ( s) => Self :: from ( s) ,
136+ Cow :: Owned ( s) => Self :: from ( s) ,
137+ }
138+ }
139+ }
140+
131141impl From < OsStr > for std:: ffi:: OsString {
132142 fn from ( name : OsStr ) -> Self {
133143 name. name . into_os_string ( )
@@ -351,4 +361,4 @@ mod tests {
351361 let osstr = OsStr :: from ( cow) ;
352362 assert_eq ! ( osstr, OsStr :: from( "world" ) ) ;
353363 }
354- }
364+ }
Original file line number Diff line number Diff line change @@ -77,6 +77,16 @@ impl From<&'_ &'static str> for Str {
7777 }
7878}
7979
80+ #[ cfg( feature = "string" ) ]
81+ impl From < Cow < ' static , str > > for Str {
82+ fn from ( cow : Cow < ' static , str > ) -> Self {
83+ match cow {
84+ Cow :: Borrowed ( s) => Self :: from ( s) ,
85+ Cow :: Owned ( s) => Self :: from ( s) ,
86+ }
87+ }
88+ }
89+
8090impl From < Str > for String {
8191 fn from ( name : Str ) -> Self {
8292 name. name . into_string ( )
@@ -316,7 +326,6 @@ impl std::hash::Hash for Inner {
316326 }
317327}
318328
319-
320329#[ cfg( test) ]
321330#[ cfg( feature = "string" ) ]
322331mod tests {
Original file line number Diff line number Diff line change @@ -186,6 +186,15 @@ impl From<&'_ &'static str> for StyledStr {
186186 }
187187}
188188
189+ impl From < Cow < ' static , str > > for StyledStr {
190+ fn from ( cow : Cow < ' static , str > ) -> Self {
191+ match cow {
192+ Cow :: Borrowed ( s) => StyledStr :: from ( s) ,
193+ Cow :: Owned ( s) => StyledStr :: from ( s) ,
194+ }
195+ }
196+ }
197+
189198impl std:: fmt:: Write for StyledStr {
190199 #[ inline]
191200 fn write_str ( & mut self , s : & str ) -> Result < ( ) , std:: fmt:: Error > {
@@ -271,4 +280,4 @@ mod tests {
271280 let styled = StyledStr :: from ( cow) ;
272281 assert_eq ! ( styled, StyledStr :: from( "world" ) ) ;
273282 }
274- }
283+ }
Original file line number Diff line number Diff line change @@ -79,6 +79,13 @@ impl From<Id> for Str {
7979 }
8080}
8181
82+ #[ cfg( feature = "string" ) ]
83+ impl From < Cow < ' static , str > > for Id {
84+ fn from ( name : Cow < ' static , str > ) -> Self {
85+ Self ( name. into ( ) )
86+ }
87+ }
88+
8289impl From < Id > for String {
8390 fn from ( name : Id ) -> Self {
8491 Str :: from ( name) . into ( )
You can’t perform that action at this time.
0 commit comments