diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2021-05-26 13:31:04 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-26 13:31:04 +0900 |
| commit | e87bc66fca0f23b1f2bc56462d0e2e7eb82a1253 (patch) | |
| tree | af62e0c6bf910985d64dfdfba5d1fc9de38cab4a /library/alloc/src | |
| parent | 750820342130a026f10c15be4ef0a200f5959be6 (diff) | |
| parent | 37588e9e1b67eca4edd4a1972040ba449c51e887 (diff) | |
| download | rust-e87bc66fca0f23b1f2bc56462d0e2e7eb82a1253.tar.gz rust-e87bc66fca0f23b1f2bc56462d0e2e7eb82a1253.zip | |
Rollup merge of #85666 - fee1-dead:document-shared-from-cow, r=dtolnay
Document shared_from_cow functions
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/rc.rs | 12 | ||||
| -rw-r--r-- | library/alloc/src/sync.rs | 12 |
2 files changed, 24 insertions, 0 deletions
diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index f19a13c8def..f131182a896 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -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 { diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 02a739309cd..a8fa028fc90 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -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 { |
