I want to reuse String
buffer as PathBuf
. For this I use From
trait conversion. If I open the source code, I'll see:
impl From<String> for PathBuf {
/// Converts a `String` into a `PathBuf`
///
/// This conversion does not allocate or copy memory.
#[inline]
fn from(s: String) -> PathBuf {
PathBuf::from(OsString::from(s))
}
}
As you can see from the comment: "This conversion does not allocate or copy memory". But is it? If I open String
to OsString
convertion, then it will be:
impl From<String> for OsString {
/// Converts a [`String`] into a [`OsString`].
///
/// The conversion copies the data, and includes an allocation on the heap.
#[inline]
fn from(s: String) -> OsString {
OsString { inner: Buf::from_string(s) }
}
}
The comment reads: "The conversion copies the data, and includes an allocation on the heap". As far as I understand, OS specific code follows deeper. In the end, can I rely on the lack of allocation on all OSs (at least on Windows, Linux, MacOS)? Anyway, isn't the documentation conflicting?