Document shared_from_cow functions

This commit is contained in:
Deadbeef 2021-05-25 20:06:02 +08:00
parent a7890c7952
commit 37588e9e1b
No known key found for this signature in database
GPG Key ID: C86982F2EDE0C128
2 changed files with 24 additions and 0 deletions

View File

@ -1859,6 +1859,18 @@ where
B: ToOwned + ?Sized,
Rc<B>: From<&'a B> + From<B::Owned>,
{
/// Create a reference-counted pointer from
/// a clone-on-write pointer by copying its content.
///
/// # Example
///
/// ```rust
/// # use std::rc::Rc;
/// # use std::borrow::Cow;
/// let cow: Cow<str> = Cow::Borrowed("eggplant");
/// let shared: Rc<str> = Rc::from(cow);
/// assert_eq!("eggplant", &shared[..]);
/// ```
#[inline]
fn from(cow: Cow<'a, B>) -> Rc<B> {
match cow {

View File

@ -2413,6 +2413,18 @@ where
B: ToOwned + ?Sized,
Arc<B>: From<&'a B> + From<B::Owned>,
{
/// Create an atomically reference-counted pointer from
/// a clone-on-write pointer by copying its content.
///
/// # Example
///
/// ```rust
/// # use std::sync::Arc;
/// # use std::borrow::Cow;
/// let cow: Cow<str> = Cow::Borrowed("eggplant");
/// let shared: Arc<str> = Arc::from(cow);
/// assert_eq!("eggplant", &shared[..]);
/// ```
#[inline]
fn from(cow: Cow<'a, B>) -> Arc<B> {
match cow {