Skip to content

Commit 2967626

Browse files
committed
Document From impls in path.rs
1 parent cdbe288 commit 2967626

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

library/std/src/path.rs

+24
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,9 @@ impl Clone for PathBuf {
14201420

14211421
#[stable(feature = "box_from_path", since = "1.17.0")]
14221422
impl From<&Path> for Box<Path> {
1423+
/// Creates a boxed [`Path`] from a reference.
1424+
///
1425+
/// This will allocate and clone `path` to it.
14231426
fn from(path: &Path) -> Box<Path> {
14241427
let boxed: Box<OsStr> = path.inner.into();
14251428
let rw = Box::into_raw(boxed) as *mut Path;
@@ -1429,6 +1432,9 @@ impl From<&Path> for Box<Path> {
14291432

14301433
#[stable(feature = "box_from_cow", since = "1.45.0")]
14311434
impl From<Cow<'_, Path>> for Box<Path> {
1435+
/// Creates a boxed [`Path`] from a clone-on-write pointer.
1436+
///
1437+
/// Converting from a `Cow::Owned` does not clone or allocate.
14321438
#[inline]
14331439
fn from(cow: Cow<'_, Path>) -> Box<Path> {
14341440
match cow {
@@ -1471,6 +1477,9 @@ impl Clone for Box<Path> {
14711477

14721478
#[stable(feature = "rust1", since = "1.0.0")]
14731479
impl<T: ?Sized + AsRef<OsStr>> From<&T> for PathBuf {
1480+
/// Converts a borrowed `OsStr` to a `PathBuf`.
1481+
///
1482+
/// Allocates a [`PathBuf`] and copies the data into it.
14741483
#[inline]
14751484
fn from(s: &T) -> PathBuf {
14761485
PathBuf::from(s.as_ref().to_os_string())
@@ -1575,6 +1584,10 @@ impl Default for PathBuf {
15751584

15761585
#[stable(feature = "cow_from_path", since = "1.6.0")]
15771586
impl<'a> From<&'a Path> for Cow<'a, Path> {
1587+
/// Creates a clone-on-write pointer from a reference to
1588+
/// [`Path`].
1589+
///
1590+
/// This conversion does not clone or allocate.
15781591
#[inline]
15791592
fn from(s: &'a Path) -> Cow<'a, Path> {
15801593
Cow::Borrowed(s)
@@ -1583,6 +1596,10 @@ impl<'a> From<&'a Path> for Cow<'a, Path> {
15831596

15841597
#[stable(feature = "cow_from_path", since = "1.6.0")]
15851598
impl<'a> From<PathBuf> for Cow<'a, Path> {
1599+
/// Creates a clone-on-write pointer from an owned
1600+
/// instance of [`PathBuf`].
1601+
///
1602+
/// This conversion does not clone or allocate.
15861603
#[inline]
15871604
fn from(s: PathBuf) -> Cow<'a, Path> {
15881605
Cow::Owned(s)
@@ -1591,6 +1608,10 @@ impl<'a> From<PathBuf> for Cow<'a, Path> {
15911608

15921609
#[stable(feature = "cow_from_pathbuf_ref", since = "1.28.0")]
15931610
impl<'a> From<&'a PathBuf> for Cow<'a, Path> {
1611+
/// Creates a clone-on-write pointer from a reference to
1612+
/// [`PathBuf`].
1613+
///
1614+
/// This conversion does not clone or allocate.
15941615
#[inline]
15951616
fn from(p: &'a PathBuf) -> Cow<'a, Path> {
15961617
Cow::Borrowed(p.as_path())
@@ -1599,6 +1620,9 @@ impl<'a> From<&'a PathBuf> for Cow<'a, Path> {
15991620

16001621
#[stable(feature = "pathbuf_from_cow_path", since = "1.28.0")]
16011622
impl<'a> From<Cow<'a, Path>> for PathBuf {
1623+
/// Converts a clone-on-write pointer to an owned path.
1624+
///
1625+
/// Converting from a `Cow::Owned` does not clone or allocate.
16021626
#[inline]
16031627
fn from(p: Cow<'a, Path>) -> Self {
16041628
p.into_owned()

0 commit comments

Comments
 (0)