Skip to content

Commit 700c83b

Browse files
author
Bastian Gruber
committed
Document From implementations
1 parent 780658a commit 700c83b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/libstd/path.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,13 +1397,17 @@ impl<'a> From<&'a Path> for Box<Path> {
13971397

13981398
#[stable(feature = "path_buf_from_box", since = "1.18.0")]
13991399
impl From<Box<Path>> for PathBuf {
1400+
/// Converts a `Box<Path>` into a `PathBuf`.
1401+
/// This conversion does not allocate memory
14001402
fn from(boxed: Box<Path>) -> PathBuf {
14011403
boxed.into_path_buf()
14021404
}
14031405
}
14041406

14051407
#[stable(feature = "box_from_path_buf", since = "1.20.0")]
14061408
impl From<PathBuf> for Box<Path> {
1409+
/// Converts a `PathBuf` into a `Box<Path>`.
1410+
/// This conversion does not allocate memory
14071411
fn from(p: PathBuf) -> Box<Path> {
14081412
p.into_boxed_path()
14091413
}
@@ -1426,20 +1430,28 @@ impl<'a, T: ?Sized + AsRef<OsStr>> From<&'a T> for PathBuf {
14261430

14271431
#[stable(feature = "rust1", since = "1.0.0")]
14281432
impl From<OsString> for PathBuf {
1433+
/// Converts a `OsString` into a `PathBuf`.
1434+
/// This conversion copies the data.
1435+
/// This conversion does allocate memory.
14291436
fn from(s: OsString) -> PathBuf {
14301437
PathBuf { inner: s }
14311438
}
14321439
}
14331440

14341441
#[stable(feature = "from_path_buf_for_os_string", since = "1.14.0")]
14351442
impl From<PathBuf> for OsString {
1443+
/// Converts a `PathBuf` into a `OsString`.
1444+
/// This conversion copies the data.
1445+
/// This conversion does allocate memory.
14361446
fn from(path_buf : PathBuf) -> OsString {
14371447
path_buf.inner
14381448
}
14391449
}
14401450

14411451
#[stable(feature = "rust1", since = "1.0.0")]
14421452
impl From<String> for PathBuf {
1453+
/// Converts a `String` into a `PathBuf`.
1454+
/// This conversion does not allocate memory
14431455
fn from(s: String) -> PathBuf {
14441456
PathBuf::from(OsString::from(s))
14451457
}
@@ -1536,6 +1548,10 @@ impl<'a> From<Cow<'a, Path>> for PathBuf {
15361548

15371549
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
15381550
impl From<PathBuf> for Arc<Path> {
1551+
/// Converts a `PathBuf` into a `Arc<Path>`.
1552+
/// This conversion happens in place.
1553+
/// This conversion does not allocate memory.
1554+
/// This function is unsafe. Data can't be moved from this reference.
15391555
#[inline]
15401556
fn from(s: PathBuf) -> Arc<Path> {
15411557
let arc: Arc<OsStr> = Arc::from(s.into_os_string());
@@ -1545,6 +1561,10 @@ impl From<PathBuf> for Arc<Path> {
15451561

15461562
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
15471563
impl<'a> From<&'a Path> for Arc<Path> {
1564+
/// Converts a `PathBuf` into a `Arc<Path>`.
1565+
/// This conversion happens in place.
1566+
/// This conversion does not allocate memory.
1567+
/// This function is unsafe. Data can't be moved from this reference.
15481568
#[inline]
15491569
fn from(s: &Path) -> Arc<Path> {
15501570
let arc: Arc<OsStr> = Arc::from(s.as_os_str());
@@ -1554,6 +1574,10 @@ impl<'a> From<&'a Path> for Arc<Path> {
15541574

15551575
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
15561576
impl From<PathBuf> for Rc<Path> {
1577+
/// Converts a `PathBuf` into a `Rc<Path>`.
1578+
/// This conversion happens in place.
1579+
/// This conversion does not allocate memory.
1580+
/// This function is unsafe. Data can't be moved from this reference.
15571581
#[inline]
15581582
fn from(s: PathBuf) -> Rc<Path> {
15591583
let rc: Rc<OsStr> = Rc::from(s.into_os_string());

0 commit comments

Comments
 (0)