Skip to content

Commit bdfdc71

Browse files
committed
Implement FromStr for OsString
1 parent 9201998 commit bdfdc71

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/libstd/ffi/os_str.rs

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::fmt;
44
use crate::hash::{Hash, Hasher};
55
use crate::ops;
66
use crate::rc::Rc;
7+
use crate::str::FromStr;
78
use crate::sync::Arc;
89

910
use crate::sys::os_str::{Buf, Slice};
@@ -1174,6 +1175,15 @@ impl AsInner<Slice> for OsStr {
11741175
}
11751176
}
11761177

1178+
#[stable(feature = "osstring_from_str", since = "1.45.0")]
1179+
impl FromStr for OsString {
1180+
type Err = core::convert::Infallible;
1181+
1182+
fn from_str(s: &str) -> Result<Self, Self::Err> {
1183+
Ok(OsString::from(s))
1184+
}
1185+
}
1186+
11771187
#[cfg(test)]
11781188
mod tests {
11791189
use super::*;

0 commit comments

Comments
 (0)