@@ -352,6 +352,15 @@ impl<'a> Iterator<char> for Decompositions<'a> {
352352/// # Return value
353353///
354354/// The original string with all occurrences of `from` replaced with `to`
355+ ///
356+ /// # Example
357+ ///
358+ /// ```rust
359+ /// use std::str;
360+ /// let string = "orange";
361+ /// let new_string = str::replace(string, "or", "str");
362+ /// assert_eq!(new_string.as_slice(), "strange");
363+ /// ```
355364pub fn replace ( s : & str , from : & str , to : & str ) -> String {
356365 let mut result = String :: new ( ) ;
357366 let mut last_end = 0 ;
@@ -573,6 +582,14 @@ pub type SendStr = MaybeOwned<'static>;
573582
574583impl < ' a > MaybeOwned < ' a > {
575584 /// Returns `true` if this `MaybeOwned` wraps an owned string
585+ ///
586+ /// # Example
587+ ///
588+ /// ```rust
589+ /// let string = String::from_str("orange");
590+ /// let maybe_owned_string = string.into_maybe_owned();
591+ /// assert_eq!(true, maybe_owned_string.is_owned());
592+ /// ```
576593 #[ inline]
577594 pub fn is_owned ( & self ) -> bool {
578595 match * self {
@@ -582,6 +599,14 @@ impl<'a> MaybeOwned<'a> {
582599 }
583600
584601 /// Returns `true` if this `MaybeOwned` wraps a borrowed string
602+ ///
603+ /// # Example
604+ ///
605+ /// ```rust
606+ /// let string = "orange";
607+ /// let maybe_owned_string = string.as_slice().into_maybe_owned();
608+ /// assert_eq!(true, maybe_owned_string.is_slice());
609+ /// ```
585610 #[ inline]
586611 pub fn is_slice ( & self ) -> bool {
587612 match * self {
@@ -597,18 +622,40 @@ pub trait IntoMaybeOwned<'a> {
597622 fn into_maybe_owned ( self ) -> MaybeOwned < ' a > ;
598623}
599624
625+ /// # Example
626+ ///
627+ /// ```rust
628+ /// let owned_string = String::from_str("orange");
629+ /// let maybe_owned_string = owned_string.into_maybe_owned();
630+ /// assert_eq!(true, maybe_owned_string.is_owned());
631+ /// ```
600632impl < ' a > IntoMaybeOwned < ' a > for String {
601633 #[ inline]
602634 fn into_maybe_owned ( self ) -> MaybeOwned < ' a > {
603635 Owned ( self )
604636 }
605637}
606638
639+ /// # Example
640+ ///
641+ /// ```rust
642+ /// let string = "orange";
643+ /// let maybe_owned_str = string.as_slice().into_maybe_owned();
644+ /// assert_eq!(false, maybe_owned_str.is_owned());
645+ /// ```
607646impl < ' a > IntoMaybeOwned < ' a > for & ' a str {
608647 #[ inline]
609648 fn into_maybe_owned ( self ) -> MaybeOwned < ' a > { Slice ( self ) }
610649}
611650
651+ /// # Example
652+ ///
653+ /// ```rust
654+ /// let str = "orange";
655+ /// let maybe_owned_str = str.as_slice().into_maybe_owned();
656+ /// let maybe_maybe_owned_str = maybe_owned_str.into_maybe_owned();
657+ /// assert_eq!(false, maybe_maybe_owned_str.is_owned());
658+ /// ```
612659impl < ' a > IntoMaybeOwned < ' a > for MaybeOwned < ' a > {
613660 #[ inline]
614661 fn into_maybe_owned ( self ) -> MaybeOwned < ' a > { self }
0 commit comments