@@ -2352,6 +2352,16 @@ impl<'a> From<Cow<'a, str>> for String {
2352
2352
2353
2353
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2354
2354
impl < ' a > From < & ' a str > for Cow < ' a , str > {
2355
+ /// Converts a string slice into a Borrowed variant.
2356
+ /// No heap allocation is performed, and the string
2357
+ /// is not copied.
2358
+ ///
2359
+ /// # Example
2360
+ ///
2361
+ /// ```
2362
+ /// # use std::borrow::Cow;
2363
+ /// assert_eq!(Cow::from("eggplant"), Cow::Borrowed("eggplant"));
2364
+ /// ```
2355
2365
#[ inline]
2356
2366
fn from ( s : & ' a str ) -> Cow < ' a , str > {
2357
2367
Cow :: Borrowed ( s)
@@ -2360,6 +2370,18 @@ impl<'a> From<&'a str> for Cow<'a, str> {
2360
2370
2361
2371
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2362
2372
impl < ' a > From < String > for Cow < ' a , str > {
2373
+ /// Converts a String into an Owned variant.
2374
+ /// No heap allocation is performed, and the string
2375
+ /// is not copied.
2376
+ ///
2377
+ /// # Example
2378
+ ///
2379
+ /// ```
2380
+ /// # use std::borrow::Cow;
2381
+ /// let s = "eggplant".to_string();
2382
+ /// let s2 = "eggplant".to_string();
2383
+ /// assert_eq!(Cow::from(s), Cow::<'static, str>::Owned(s2));
2384
+ /// ```
2363
2385
#[ inline]
2364
2386
fn from ( s : String ) -> Cow < ' a , str > {
2365
2387
Cow :: Owned ( s)
@@ -2368,6 +2390,17 @@ impl<'a> From<String> for Cow<'a, str> {
2368
2390
2369
2391
#[ stable( feature = "cow_from_string_ref" , since = "1.28.0" ) ]
2370
2392
impl < ' a > From < & ' a String > for Cow < ' a , str > {
2393
+ /// Converts a String reference into a Borrowed variant.
2394
+ /// No heap allocation is performed, and the string
2395
+ /// is not copied.
2396
+ ///
2397
+ /// # Example
2398
+ ///
2399
+ /// ```
2400
+ /// # use std::borrow::Cow;
2401
+ /// let s = "eggplant".to_string();
2402
+ /// assert_eq!(Cow::from(&s), Cow::Borrowed("eggplant"));
2403
+ /// ```
2371
2404
#[ inline]
2372
2405
fn from ( s : & ' a String ) -> Cow < ' a , str > {
2373
2406
Cow :: Borrowed ( s. as_str ( ) )
0 commit comments