@@ -351,6 +351,15 @@ impl<'a> Iterator<char> for Decompositions<'a> {
351
351
/// # Return value
352
352
///
353
353
/// The original string with all occurrences of `from` replaced with `to`
354
+ ///
355
+ /// # Example
356
+ ///
357
+ /// ```rust
358
+ /// use std::str;
359
+ /// let string = "orange";
360
+ /// let new_string = str::replace(string, "or", "str");
361
+ /// assert_eq!(new_string.as_slice(), "strange");
362
+ /// ```
354
363
pub fn replace ( s : & str , from : & str , to : & str ) -> String {
355
364
let mut result = String :: new ( ) ;
356
365
let mut last_end = 0 ;
@@ -572,6 +581,14 @@ pub type SendStr = MaybeOwned<'static>;
572
581
573
582
impl < ' a > MaybeOwned < ' a > {
574
583
/// Returns `true` if this `MaybeOwned` wraps an owned string
584
+ ///
585
+ /// # Example
586
+ ///
587
+ /// ```rust
588
+ /// let string = String::from_str("orange");
589
+ /// let maybe_owned_string = string.into_maybe_owned();
590
+ /// assert_eq!(true, maybe_owned_string.is_owned());
591
+ /// ```
575
592
#[ inline]
576
593
pub fn is_owned ( & self ) -> bool {
577
594
match * self {
@@ -581,6 +598,14 @@ impl<'a> MaybeOwned<'a> {
581
598
}
582
599
583
600
/// Returns `true` if this `MaybeOwned` wraps a borrowed string
601
+ ///
602
+ /// # Example
603
+ ///
604
+ /// ```rust
605
+ /// let string = "orange";
606
+ /// let maybe_owned_string = string.as_slice().into_maybe_owned();
607
+ /// assert_eq!(true, maybe_owned_string.is_slice());
608
+ /// ```
584
609
#[ inline]
585
610
pub fn is_slice ( & self ) -> bool {
586
611
match * self {
@@ -596,18 +621,40 @@ pub trait IntoMaybeOwned<'a> {
596
621
fn into_maybe_owned ( self ) -> MaybeOwned < ' a > ;
597
622
}
598
623
624
+ /// # Example
625
+ ///
626
+ /// ```rust
627
+ /// let owned_string = String::from_str("orange");
628
+ /// let maybe_owned_string = owned_string.into_maybe_owned();
629
+ /// assert_eq!(true, maybe_owned_string.is_owned());
630
+ /// ```
599
631
impl < ' a > IntoMaybeOwned < ' a > for String {
600
632
#[ inline]
601
633
fn into_maybe_owned ( self ) -> MaybeOwned < ' a > {
602
634
Owned ( self )
603
635
}
604
636
}
605
637
638
+ /// # Example
639
+ ///
640
+ /// ```rust
641
+ /// let string = "orange";
642
+ /// let maybe_owned_str = string.as_slice().into_maybe_owned();
643
+ /// assert_eq!(false, maybe_owned_str.is_owned());
644
+ /// ```
606
645
impl < ' a > IntoMaybeOwned < ' a > for & ' a str {
607
646
#[ inline]
608
647
fn into_maybe_owned ( self ) -> MaybeOwned < ' a > { Slice ( self ) }
609
648
}
610
649
650
+ /// # Example
651
+ ///
652
+ /// ```rust
653
+ /// let str = "orange";
654
+ /// let maybe_owned_str = str.as_slice().into_maybe_owned();
655
+ /// let maybe_maybe_owned_str = maybe_owned_str.into_maybe_owned();
656
+ /// assert_eq!(false, maybe_maybe_owned_str.is_owned());
657
+ /// ```
611
658
impl < ' a > IntoMaybeOwned < ' a > for MaybeOwned < ' a > {
612
659
#[ inline]
613
660
fn into_maybe_owned ( self ) -> MaybeOwned < ' a > { self }
0 commit comments