@@ -2285,6 +2285,16 @@ impl<T> From<T> for Arc<T> {
2285
2285
2286
2286
#[ stable( feature = "shared_from_slice" , since = "1.21.0" ) ]
2287
2287
impl < T : Clone > From < & [ T ] > for Arc < [ T ] > {
2288
+ /// Allocate a reference-counted slice and fill it by cloning `v`'s items.
2289
+ ///
2290
+ /// # Example
2291
+ ///
2292
+ /// ```
2293
+ /// # use std::sync::Arc;
2294
+ /// let original: &[i32] = &[1, 2, 3];
2295
+ /// let shared: Arc<[i32]> = Arc::from(original);
2296
+ /// assert_eq!(&[1, 2, 3], &shared[..]);
2297
+ /// ```
2288
2298
#[ inline]
2289
2299
fn from ( v : & [ T ] ) -> Arc < [ T ] > {
2290
2300
<Self as ArcFromSlice < T > >:: from_slice ( v)
@@ -2293,6 +2303,15 @@ impl<T: Clone> From<&[T]> for Arc<[T]> {
2293
2303
2294
2304
#[ stable( feature = "shared_from_slice" , since = "1.21.0" ) ]
2295
2305
impl From < & str > for Arc < str > {
2306
+ /// Allocate a reference-counted `str` and copy `v` into it.
2307
+ ///
2308
+ /// # Example
2309
+ ///
2310
+ /// ```
2311
+ /// # use std::sync::Arc;
2312
+ /// let shared: Arc<str> = Arc::from("eggplant");
2313
+ /// assert_eq!("eggplant", &shared[..]);
2314
+ /// ```
2296
2315
#[ inline]
2297
2316
fn from ( v : & str ) -> Arc < str > {
2298
2317
let arc = Arc :: < [ u8 ] > :: from ( v. as_bytes ( ) ) ;
@@ -2302,6 +2321,16 @@ impl From<&str> for Arc<str> {
2302
2321
2303
2322
#[ stable( feature = "shared_from_slice" , since = "1.21.0" ) ]
2304
2323
impl From < String > for Arc < str > {
2324
+ /// Allocate a reference-counted `str` and copy `v` into it.
2325
+ ///
2326
+ /// # Example
2327
+ ///
2328
+ /// ```
2329
+ /// # use std::sync::Arc;
2330
+ /// let unique: String = "eggplant".to_owned();
2331
+ /// let shared: Arc<str> = Arc::from(unique);
2332
+ /// assert_eq!("eggplant", &shared[..]);
2333
+ /// ```
2305
2334
#[ inline]
2306
2335
fn from ( v : String ) -> Arc < str > {
2307
2336
Arc :: from ( & v[ ..] )
@@ -2310,6 +2339,16 @@ impl From<String> for Arc<str> {
2310
2339
2311
2340
#[ stable( feature = "shared_from_slice" , since = "1.21.0" ) ]
2312
2341
impl < T : ?Sized > From < Box < T > > for Arc < T > {
2342
+ /// Move a boxed object to a new, reference-counted allocation.
2343
+ ///
2344
+ /// # Example
2345
+ ///
2346
+ /// ```
2347
+ /// # use std::sync::Arc;
2348
+ /// let unique: Box<str> = Box::from("eggplant");
2349
+ /// let shared: Arc<str> = Arc::from(unique);
2350
+ /// assert_eq!("eggplant", &shared[..]);
2351
+ /// ```
2313
2352
#[ inline]
2314
2353
fn from ( v : Box < T > ) -> Arc < T > {
2315
2354
Arc :: from_box ( v)
@@ -2318,6 +2357,16 @@ impl<T: ?Sized> From<Box<T>> for Arc<T> {
2318
2357
2319
2358
#[ stable( feature = "shared_from_slice" , since = "1.21.0" ) ]
2320
2359
impl < T > From < Vec < T > > for Arc < [ T ] > {
2360
+ /// Allocate a reference-counted slice and move `v`'s items into it.
2361
+ ///
2362
+ /// # Example
2363
+ ///
2364
+ /// ```
2365
+ /// # use std::sync::Arc;
2366
+ /// let unique: Vec<i32> = vec![1, 2, 3];
2367
+ /// let shared: Arc<[i32]> = Arc::from(unique);
2368
+ /// assert_eq!(&[1, 2, 3], &shared[..]);
2369
+ /// ```
2321
2370
#[ inline]
2322
2371
fn from ( mut v : Vec < T > ) -> Arc < [ T ] > {
2323
2372
unsafe {
0 commit comments