@@ -3544,6 +3544,8 @@ impl str {
3544
3544
///
3545
3545
/// assert_eq!("Hello\tworld", s.trim());
3546
3546
/// ```
3547
+ #[ must_use = "this returns the trimmed string as a new allocation, \
3548
+ without modifying the original"]
3547
3549
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
3548
3550
pub fn trim ( & self ) -> & str {
3549
3551
self . trim_matches ( |c : char | c. is_whitespace ( ) )
@@ -3579,6 +3581,8 @@ impl str {
3579
3581
/// let s = " עברית ";
3580
3582
/// assert!(Some('ע') == s.trim_start().chars().next());
3581
3583
/// ```
3584
+ #[ must_use = "this returns the trimmed string as a new allocation, \
3585
+ without modifying the original"]
3582
3586
#[ stable( feature = "trim_direction" , since = "1.30.0" ) ]
3583
3587
pub fn trim_start ( & self ) -> & str {
3584
3588
self . trim_start_matches ( |c : char | c. is_whitespace ( ) )
@@ -3614,6 +3618,8 @@ impl str {
3614
3618
/// let s = " עברית ";
3615
3619
/// assert!(Some('ת') == s.trim_end().chars().rev().next());
3616
3620
/// ```
3621
+ #[ must_use = "this returns the trimmed string as a new allocation, \
3622
+ without modifying the original"]
3617
3623
#[ stable( feature = "trim_direction" , since = "1.30.0" ) ]
3618
3624
pub fn trim_end ( & self ) -> & str {
3619
3625
self . trim_end_matches ( |c : char | c. is_whitespace ( ) )
@@ -3716,6 +3722,8 @@ impl str {
3716
3722
/// ```
3717
3723
/// assert_eq!("1foo1barXX".trim_matches(|c| c == '1' || c == 'X'), "foo1bar");
3718
3724
/// ```
3725
+ #[ must_use = "this returns the trimmed string as a new allocation, \
3726
+ without modifying the original"]
3719
3727
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
3720
3728
pub fn trim_matches < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> & ' a str
3721
3729
where P :: Searcher : DoubleEndedSearcher < ' a >
@@ -3761,6 +3769,8 @@ impl str {
3761
3769
/// let x: &[_] = &['1', '2'];
3762
3770
/// assert_eq!("12foo1bar12".trim_start_matches(x), "foo1bar12");
3763
3771
/// ```
3772
+ #[ must_use = "this returns the trimmed string as a new allocation, \
3773
+ without modifying the original"]
3764
3774
#[ stable( feature = "trim_direction" , since = "1.30.0" ) ]
3765
3775
pub fn trim_start_matches < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> & ' a str {
3766
3776
let mut i = self . len ( ) ;
@@ -3804,6 +3814,8 @@ impl str {
3804
3814
/// ```
3805
3815
/// assert_eq!("1fooX".trim_end_matches(|c| c == '1' || c == 'X'), "1foo");
3806
3816
/// ```
3817
+ #[ must_use = "this returns the trimmed string as a new allocation, \
3818
+ without modifying the original"]
3807
3819
#[ stable( feature = "trim_direction" , since = "1.30.0" ) ]
3808
3820
pub fn trim_end_matches < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> & ' a str
3809
3821
where P :: Searcher : ReverseSearcher < ' a >
0 commit comments