Possible Mistake in OsString Documentation

While browsing the OsString documentation I found this bit about converting from String to OsString:

From a Rust string: OsString implements From<String>, so you can use my_string.from to create an OsString from a normal Rust string.

This didn't look right to me, so I tried the following in on the playground:

use std::ffi::OsString;

fn foo(_: OsString) { }

pub fn main() {
    let string = String::new();
    foo(string.from());
}

...which failed to compile. However changing the .from() call to .into() does work:

use std::ffi::OsString;

fn foo(_: OsString) { }

pub fn main() {
    let string = String::new();
    foo(string.into());
}

So I think the docs actually meant to say:

From a Rust string: OsString implements From<String>, so you can use my_string.into() to create an OsString from a normal Rust string.

Is there something I'm missing here?

1 Like

It looks like @steffahn did a drive by fix in PR #88343, which will land in Rust 1.57.0.

2 Likes

Oh, I didn't know that this had already been addressed. Thanks for pointing that out!

In case it's helpful in the future, I'll mention that you can view the latest pre-release documentation by adding "nightly" to the url. E.g. https://doc.rust-lang.org/nightly/std/ffi/struct.OsString.html#creating-an-osstring

6 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.