@@ -1094,13 +1094,25 @@ pub trait StrSlice<'a> {
1094
1094
/// # Arguments
1095
1095
///
1096
1096
/// - needle - The string to look for
1097
+ ///
1098
+ /// # Example
1099
+ ///
1100
+ /// ```rust
1101
+ /// assert!("bananas".contains("nana"));
1102
+ /// ```
1097
1103
fn contains < ' a > ( & self , needle : & ' a str ) -> bool ;
1098
1104
1099
1105
/// Returns true if a string contains a char.
1100
1106
///
1101
1107
/// # Arguments
1102
1108
///
1103
1109
/// - needle - The char to look for
1110
+ ///
1111
+ /// # Example
1112
+ ///
1113
+ /// ```rust
1114
+ /// assert!("hello".contains_char('e'));
1115
+ /// ```
1104
1116
fn contains_char ( & self , needle : char ) -> bool ;
1105
1117
1106
1118
/// An iterator over the characters of `self`. Note, this iterates
@@ -1115,6 +1127,13 @@ pub trait StrSlice<'a> {
1115
1127
fn chars ( & self ) -> Chars < ' a > ;
1116
1128
1117
1129
/// An iterator over the bytes of `self`
1130
+ ///
1131
+ /// # Example
1132
+ ///
1133
+ /// ```rust
1134
+ /// let v: Vec<u8> = "bors".bytes().collect();
1135
+ /// assert_eq!(v, b"bors".to_vec());
1136
+ /// ```
1118
1137
fn bytes ( & self ) -> Bytes < ' a > ;
1119
1138
1120
1139
/// An iterator over the characters of `self` and their byte offsets.
@@ -1381,9 +1400,21 @@ pub trait StrSlice<'a> {
1381
1400
fn slice_chars ( & self , begin : uint , end : uint ) -> & ' a str ;
1382
1401
1383
1402
/// Returns true if `needle` is a prefix of the string.
1403
+ ///
1404
+ /// # Example
1405
+ ///
1406
+ /// ```rust
1407
+ /// assert!("banana".starts_with("ba"));
1408
+ /// ```
1384
1409
fn starts_with ( & self , needle : & str ) -> bool ;
1385
1410
1386
1411
/// Returns true if `needle` is a suffix of the string.
1412
+ ///
1413
+ /// # Example
1414
+ ///
1415
+ /// ```rust
1416
+ /// assert!("banana".ends_with("nana"));
1417
+ /// ```
1387
1418
fn ends_with ( & self , needle : & str ) -> bool ;
1388
1419
1389
1420
/// Returns a string with characters that match `to_trim` removed.
@@ -1525,6 +1556,15 @@ pub trait StrSlice<'a> {
1525
1556
1526
1557
/// Plucks the character starting at the `i`th byte of a string.
1527
1558
///
1559
+ /// # Example
1560
+ ///
1561
+ /// ```rust
1562
+ /// let s = "abπc";
1563
+ /// assert_eq!(s.char_at(1), 'b');
1564
+ /// assert_eq!(s.char_at(2), 'π');
1565
+ /// assert_eq!(s.char_at(4), 'c');
1566
+ /// ```
1567
+ ///
1528
1568
/// # Failure
1529
1569
///
1530
1570
/// If `i` is greater than or equal to the length of the string.
@@ -1540,6 +1580,12 @@ pub trait StrSlice<'a> {
1540
1580
fn char_at_reverse ( & self , i : uint ) -> char ;
1541
1581
1542
1582
/// Work with the byte buffer of a string as a byte slice.
1583
+ ///
1584
+ /// # Example
1585
+ ///
1586
+ /// ```rust
1587
+ /// assert_eq!("bors".as_bytes(), b"bors");
1588
+ /// ```
1543
1589
fn as_bytes ( & self ) -> & ' a [ u8 ] ;
1544
1590
1545
1591
/// Returns the byte index of the first character of `self` that
0 commit comments