2016-09-11 13:41:24 -05:00
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< meta name = "generator" content = "rustdoc" >
< meta name = "description" content = "API documentation for the Rust `TopLevel` enum in crate `mime`." >
< meta name = "keywords" content = "rust, rustlang, rust-lang, TopLevel" >
< title > mime::TopLevel - Rust< / title >
< link rel = "stylesheet" type = "text/css" href = "../rustdoc.css" >
< link rel = "stylesheet" type = "text/css" href = "../main.css" >
< / head >
< body class = "rustdoc" >
<!-- [if lte IE 8]>
< div class = "warning" >
This old browser is unsupported and will most likely display funky
things.
< / div >
<![endif]-->
< nav class = "sidebar" >
< p class = 'location' > < a href = 'index.html' > mime< / a > < / p > < script > window . sidebarCurrent = { name : 'TopLevel' , ty : 'enum' , relpath : '' } ; < / script > < script defer src = "sidebar-items.js" > < / script >
< / nav >
< nav class = "sub" >
< form class = "search-form js-only" >
< div class = "search-container" >
< input class = "search-input" name = "search"
autocomplete="off"
placeholder="Click or press ‘ S’ to search, ‘ ?’ for more options…"
type="search">
< / div >
< / form >
< / nav >
< section id = 'main' class = "content enum" >
< h1 class = 'fqn' > < span class = 'in-band' > Enum < a href = 'index.html' > mime< / a > ::< wbr > < a class = 'enum' href = '' > TopLevel< / a > < / span > < span class = 'out-of-band' > < span id = 'render-detail' >
< a id = "toggle-all-docs" href = "javascript:void(0)" title = "collapse all docs" >
[< span class = 'inner' > − < / span > ]
< / a >
< / span > < a id = 'src-82' class = 'srclink' href = '../src/mime/lib.rs.html#139-142' title = 'goto source code' > [src]< / a > < / span > < / h1 >
< pre class = 'rust enum' > pub enum TopLevel {
Star,
Text,
Image,
Audio,
Video,
Application,
Multipart,
Message,
Model,
Ext(< a class = 'struct' href = 'https://doc.rust-lang.org/nightly/collections/string/struct.String.html' title = 'collections::string::String' > String< / a > ),
}< / pre > < h2 class = 'variants' > Variants< / h2 >
< span id = 'variant.Star' class = 'variant' > < code > Star< / code > < / span > < span id = 'variant.Text' class = 'variant' > < code > Text< / code > < / span > < span id = 'variant.Image' class = 'variant' > < code > Image< / code > < / span > < span id = 'variant.Audio' class = 'variant' > < code > Audio< / code > < / span > < span id = 'variant.Video' class = 'variant' > < code > Video< / code > < / span > < span id = 'variant.Application' class = 'variant' > < code > Application< / code > < / span > < span id = 'variant.Multipart' class = 'variant' > < code > Multipart< / code > < / span > < span id = 'variant.Message' class = 'variant' > < code > Message< / code > < / span > < span id = 'variant.Model' class = 'variant' > < code > Model< / code > < / span > < span id = 'variant.Ext' class = 'variant' > < code > Ext(< a class = 'struct' href = 'https://doc.rust-lang.org/nightly/collections/string/struct.String.html' title = 'collections::string::String' > String< / a > )< / code > < / span > < h2 id = 'methods' > Methods< / h2 > < h3 class = 'impl' > < span class = 'in-band' > < code > impl < a class = 'enum' href = '../mime/enum.TopLevel.html' title = 'mime::TopLevel' > TopLevel< / a > < / code > < / span > < span class = 'out-of-band' > < div class = 'ghost' > < / div > < a id = 'src-94' class = 'srclink' href = '../src/mime/lib.rs.html#144-151' title = 'goto source code' > [src]< / a > < / span > < / h3 >
< div class = 'impl-items' > < h4 id = 'method.as_str' class = 'method' > < code > fn < a href = '#method.as_str' class = 'fnname' > as_str< / a > (& self) -> & < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > < / code > < / h4 >
< / div > < h2 id = 'deref-methods' > Methods from < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/ops/trait.Deref.html' title = 'core::ops::Deref' > Deref< / a > < Target=< a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > > < / h2 > < div class = 'impl-items' > < h4 id = 'method.len' class = 'method' > < code > fn < a href = '#method.len' class = 'fnname' > len< / a > (& self) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.usize.html' > usize< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns the length of < code > self< / code > .< / p >
< p > This length is in bytes, not < a href = "primitive.char.html" > < code > char< / code > < / a > s or graphemes. In other words,
it may not be what a human considers the length of the string.< / p >
< h1 id = 'examples' class = 'section-header' > < a href = '#examples' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > len< / span > < span class = 'op' > =< / span > < span class = 'string' > " foo" < / span > .< span class = 'ident' > len< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'number' > 3< / span > , < span class = 'ident' > len< / span > );
< span class = 'kw' > let< / span > < span class = 'ident' > len< / span > < span class = 'op' > =< / span > < span class = 'string' > " ƒoo" < / span > .< span class = 'ident' > len< / span > (); < span class = 'comment' > // fancy f!< / span >
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'number' > 4< / span > , < span class = 'ident' > len< / span > );< / pre >
< / div > < h4 id = 'method.is_empty' class = 'method' > < code > fn < a href = '#method.is_empty' class = 'fnname' > is_empty< / a > (& self) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.bool.html' > bool< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns true if this slice has a length of zero bytes.< / p >
< h1 id = 'examples-1' class = 'section-header' > < a href = '#examples-1' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " " < / span > ;
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > s< / span > .< span class = 'ident' > is_empty< / span > ());
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " not empty" < / span > ;
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'op' > !< / span > < span class = 'ident' > s< / span > .< span class = 'ident' > is_empty< / span > ());< / pre >
< / div > < h4 id = 'method.is_char_boundary' class = 'method' > < code > fn < a href = '#method.is_char_boundary' class = 'fnname' > is_char_boundary< / a > (& self, index: < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.usize.html' > usize< / a > ) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.bool.html' > bool< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.9.0' > 1.9.0< / div > < / h4 >
< div class = 'docblock' > < p > Checks that < code > index< / code > -th byte lies at the start and/or end of a
UTF-8 code point sequence.< / p >
< p > The start and end of the string (when < code > index == self.len()< / code > ) are
considered to be
boundaries.< / p >
< p > Returns < code > false< / code > if < code > index< / code > is greater than < code > self.len()< / code > .< / p >
< h1 id = 'examples-2' class = 'section-header' > < a href = '#examples-2' > Examples< / a > < / h1 >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " Löwe 老虎 Léopard" < / span > ;
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > s< / span > .< span class = 'ident' > is_char_boundary< / span > (< span class = 'number' > 0< / span > ));
< span class = 'comment' > // start of `老`< / span >
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > s< / span > .< span class = 'ident' > is_char_boundary< / span > (< span class = 'number' > 6< / span > ));
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > s< / span > .< span class = 'ident' > is_char_boundary< / span > (< span class = 'ident' > s< / span > .< span class = 'ident' > len< / span > ()));
< span class = 'comment' > // second byte of `ö`< / span >
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'op' > !< / span > < span class = 'ident' > s< / span > .< span class = 'ident' > is_char_boundary< / span > (< span class = 'number' > 2< / span > ));
< span class = 'comment' > // third byte of `老`< / span >
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'op' > !< / span > < span class = 'ident' > s< / span > .< span class = 'ident' > is_char_boundary< / span > (< span class = 'number' > 8< / span > ));< / pre >
< / div > < h4 id = 'method.as_bytes' class = 'method' > < code > fn < a href = '#method.as_bytes' class = 'fnname' > as_bytes< / a > (& self) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.slice.html' > & [< / a > < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.u8.html' > u8< / a > < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.slice.html' > ]< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Converts a string slice to a byte slice.< / p >
< h1 id = 'examples-3' class = 'section-header' > < a href = '#examples-3' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > bytes< / span > < span class = 'op' > =< / span > < span class = 'string' > " bors" < / span > .< span class = 'ident' > as_bytes< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > b" bors" < / span > , < span class = 'ident' > bytes< / span > );< / pre >
< / div > < h4 id = 'method.as_ptr' class = 'method' > < code > fn < a href = '#method.as_ptr' class = 'fnname' > as_ptr< / a > (& self) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.pointer.html' > *const < / a > < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.u8.html' > u8< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Converts a string slice to a raw pointer.< / p >
< p > As string slices are a slice of bytes, the raw pointer points to a
< a href = "primitive.u8.html" > < code > u8< / code > < / a > . This pointer will be pointing to the first byte of the string
slice.< / p >
< h1 id = 'examples-4' class = 'section-header' > < a href = '#examples-4' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " Hello" < / span > ;
< span class = 'kw' > let< / span > < span class = 'ident' > ptr< / span > < span class = 'op' > =< / span > < span class = 'ident' > s< / span > .< span class = 'ident' > as_ptr< / span > ();< / pre >
< / div > < h4 id = 'method.slice_unchecked' class = 'method' > < code > unsafe fn < a href = '#method.slice_unchecked' class = 'fnname' > slice_unchecked< / a > (& self, begin: < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.usize.html' > usize< / a > , end: < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.usize.html' > usize< / a > ) -> & < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Creates a string slice from another string slice, bypassing safety
checks.< / p >
< p > This new slice goes from < code > begin< / code > to < code > end< / code > , including < code > begin< / code > but
excluding < code > end< / code > .< / p >
< p > To get a mutable string slice instead, see the
< a href = "#method.slice_mut_unchecked" > < code > slice_mut_unchecked()< / code > < / a > method.< / p >
< h1 id = 'safety' class = 'section-header' > < a href = '#safety' > Safety< / a > < / h1 >
< p > Callers of this function are responsible that three preconditions are
satisfied:< / p >
< ul >
< li > < code > begin< / code > must come before < code > end< / code > .< / li >
< li > < code > begin< / code > and < code > end< / code > must be byte positions within the string slice.< / li >
< li > < code > begin< / code > and < code > end< / code > must lie on UTF-8 sequence boundaries.< / li >
< / ul >
< h1 id = 'examples-5' class = 'section-header' > < a href = '#examples-5' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " Löwe 老虎 Léopard" < / span > ;
< span class = 'kw' > unsafe< / span > {
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " Löwe 老虎 Léopard" < / span > , < span class = 'ident' > s< / span > .< span class = 'ident' > slice_unchecked< / span > (< span class = 'number' > 0< / span > , < span class = 'number' > 21< / span > ));
}
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " Hello, world!" < / span > ;
< span class = 'kw' > unsafe< / span > {
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " world" < / span > , < span class = 'ident' > s< / span > .< span class = 'ident' > slice_unchecked< / span > (< span class = 'number' > 7< / span > , < span class = 'number' > 12< / span > ));
}< / pre >
< / div > < h4 id = 'method.slice_mut_unchecked' class = 'method' > < code > unsafe fn < a href = '#method.slice_mut_unchecked' class = 'fnname' > slice_mut_unchecked< / a > (& mut self, begin: < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.usize.html' > usize< / a > , end: < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.usize.html' > usize< / a > ) -> & mut < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.5.0' > 1.5.0< / div > < / h4 >
< div class = 'docblock' > < p > Creates a string slice from another string slice, bypassing safety
checks.< / p >
< p > This new slice goes from < code > begin< / code > to < code > end< / code > , including < code > begin< / code > but
excluding < code > end< / code > .< / p >
< p > To get an immutable string slice instead, see the
< a href = "#method.slice_unchecked" > < code > slice_unchecked()< / code > < / a > method.< / p >
< h1 id = 'safety-1' class = 'section-header' > < a href = '#safety-1' > Safety< / a > < / h1 >
< p > Callers of this function are responsible that three preconditions are
satisfied:< / p >
< ul >
< li > < code > begin< / code > must come before < code > end< / code > .< / li >
< li > < code > begin< / code > and < code > end< / code > must be byte positions within the string slice.< / li >
< li > < code > begin< / code > and < code > end< / code > must lie on UTF-8 sequence boundaries.< / li >
< / ul >
< / div > < h4 id = 'method.split_at' class = 'method' > < code > fn < a href = '#method.split_at' class = 'fnname' > split_at< / a > (& self, mid: < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.usize.html' > usize< / a > ) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.tuple.html' > (< / a > & < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > , & < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.tuple.html' > )< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.4.0' > 1.4.0< / div > < / h4 >
< div class = 'docblock' > < p > Divide one string slice into two at an index.< / p >
< p > The argument, < code > mid< / code > , should be a byte offset from the start of the
string. It must also be on the boundary of a UTF-8 code point.< / p >
< p > The two slices returned go from the start of the string slice to < code > mid< / code > ,
and from < code > mid< / code > to the end of the string slice.< / p >
< p > To get mutable string slices instead, see the < a href = "#method.split_at_mut" > < code > split_at_mut()< / code > < / a >
method.< / p >
< h1 id = 'panics' class = 'section-header' > < a href = '#panics' > Panics< / a > < / h1 >
< p > Panics if < code > mid< / code > is not on a UTF-8 code point boundary, or if it is
beyond the last code point of the string slice.< / p >
< h1 id = 'examples-6' class = 'section-header' > < a href = '#examples-6' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " Per Martin-Löf" < / span > ;
< span class = 'kw' > let< / span > (< span class = 'ident' > first< / span > , < span class = 'ident' > last< / span > ) < span class = 'op' > =< / span > < span class = 'ident' > s< / span > .< span class = 'ident' > split_at< / span > (< span class = 'number' > 3< / span > );
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " Per" < / span > , < span class = 'ident' > first< / span > );
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " Martin-Löf" < / span > , < span class = 'ident' > last< / span > );< / pre >
< / div > < h4 id = 'method.split_at_mut' class = 'method' > < code > fn < a href = '#method.split_at_mut' class = 'fnname' > split_at_mut< / a > (& mut self, mid: < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.usize.html' > usize< / a > ) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.tuple.html' > (< / a > & mut < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > , & mut < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.tuple.html' > )< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.4.0' > 1.4.0< / div > < / h4 >
< div class = 'docblock' > < p > Divide one mutable string slice into two at an index.< / p >
< p > The argument, < code > mid< / code > , should be a byte offset from the start of the
string. It must also be on the boundary of a UTF-8 code point.< / p >
< p > The two slices returned go from the start of the string slice to < code > mid< / code > ,
and from < code > mid< / code > to the end of the string slice.< / p >
< p > To get immutable string slices instead, see the < a href = "#method.split_at" > < code > split_at()< / code > < / a > method.< / p >
< h1 id = 'panics-1' class = 'section-header' > < a href = '#panics-1' > Panics< / a > < / h1 >
< p > Panics if < code > mid< / code > is not on a UTF-8 code point boundary, or if it is
beyond the last code point of the string slice.< / p >
< h1 id = 'examples-7' class = 'section-header' > < a href = '#examples-7' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'kw-2' > mut< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " Per Martin-Löf" < / span > .< span class = 'ident' > to_string< / span > ();
< span class = 'kw' > let< / span > (< span class = 'ident' > first< / span > , < span class = 'ident' > last< / span > ) < span class = 'op' > =< / span > < span class = 'ident' > s< / span > .< span class = 'ident' > split_at_mut< / span > (< span class = 'number' > 3< / span > );
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " Per" < / span > , < span class = 'ident' > first< / span > );
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " Martin-Löf" < / span > , < span class = 'ident' > last< / span > );< / pre >
< / div > < h4 id = 'method.chars' class = 'method' > < code > fn < a href = '#method.chars' class = 'fnname' > chars< / a > (& self) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/str/struct.Chars.html' title = 'core::str::Chars' > Chars< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns an iterator over the < code > char< / code > s of a string slice.< / p >
< p > As a string slice consists of valid UTF-8, we can iterate through a
string slice by < a href = "primitive.char.html" > < code > char< / code > < / a > . This method returns such an iterator.< / p >
< p > It' s important to remember that < a href = "primitive.char.html" > < code > char< / code > < / a > represents a Unicode Scalar
Value, and may not match your idea of what a ' character' is. Iteration
over grapheme clusters may be what you actually want.< / p >
< h1 id = 'examples-8' class = 'section-header' > < a href = '#examples-8' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > word< / span > < span class = 'op' > =< / span > < span class = 'string' > " goodbye" < / span > ;
< span class = 'kw' > let< / span > < span class = 'ident' > count< / span > < span class = 'op' > =< / span > < span class = 'ident' > word< / span > .< span class = 'ident' > chars< / span > ().< span class = 'ident' > count< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'number' > 7< / span > , < span class = 'ident' > count< / span > );
< span class = 'kw' > let< / span > < span class = 'kw-2' > mut< / span > < span class = 'ident' > chars< / span > < span class = 'op' > =< / span > < span class = 'ident' > word< / span > .< span class = 'ident' > chars< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > ' g' < / span > ), < span class = 'ident' > chars< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > ' o' < / span > ), < span class = 'ident' > chars< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > ' o' < / span > ), < span class = 'ident' > chars< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > ' d' < / span > ), < span class = 'ident' > chars< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > ' b' < / span > ), < span class = 'ident' > chars< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > ' y' < / span > ), < span class = 'ident' > chars< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > ' e' < / span > ), < span class = 'ident' > chars< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > None< / span > , < span class = 'ident' > chars< / span > .< span class = 'ident' > next< / span > ());< / pre >
< p > Remember, < a href = "primitive.char.html" > < code > char< / code > < / a > s may not match your human intuition about characters:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > y< / span > < span class = 'op' > =< / span > < span class = 'string' > " y̆" < / span > ;
< span class = 'kw' > let< / span > < span class = 'kw-2' > mut< / span > < span class = 'ident' > chars< / span > < span class = 'op' > =< / span > < span class = 'ident' > y< / span > .< span class = 'ident' > chars< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > ' y' < / span > ), < span class = 'ident' > chars< / span > .< span class = 'ident' > next< / span > ()); < span class = 'comment' > // not ' y̆' < / span >
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > ' \u{0306}' < / span > ), < span class = 'ident' > chars< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > None< / span > , < span class = 'ident' > chars< / span > .< span class = 'ident' > next< / span > ());< / pre >
< / div > < h4 id = 'method.char_indices' class = 'method' > < code > fn < a href = '#method.char_indices' class = 'fnname' > char_indices< / a > (& self) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/str/struct.CharIndices.html' title = 'core::str::CharIndices' > CharIndices< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns an iterator over the < a href = "primitive.char.html" > < code > char< / code > < / a > s of a string slice, and their
positions.< / p >
< p > As a string slice consists of valid UTF-8, we can iterate through a
string slice by < a href = "primitive.char.html" > < code > char< / code > < / a > . This method returns an iterator of both
these < a href = "primitive.char.html" > < code > char< / code > < / a > s, as well as their byte positions.< / p >
< p > The iterator yields tuples. The position is first, the < a href = "primitive.char.html" > < code > char< / code > < / a > is
second.< / p >
< h1 id = 'examples-9' class = 'section-header' > < a href = '#examples-9' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > word< / span > < span class = 'op' > =< / span > < span class = 'string' > " goodbye" < / span > ;
< span class = 'kw' > let< / span > < span class = 'ident' > count< / span > < span class = 'op' > =< / span > < span class = 'ident' > word< / span > .< span class = 'ident' > char_indices< / span > ().< span class = 'ident' > count< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'number' > 7< / span > , < span class = 'ident' > count< / span > );
< span class = 'kw' > let< / span > < span class = 'kw-2' > mut< / span > < span class = 'ident' > char_indices< / span > < span class = 'op' > =< / span > < span class = 'ident' > word< / span > .< span class = 'ident' > char_indices< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > ((< span class = 'number' > 0< / span > , < span class = 'string' > ' g' < / span > )), < span class = 'ident' > char_indices< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > ((< span class = 'number' > 1< / span > , < span class = 'string' > ' o' < / span > )), < span class = 'ident' > char_indices< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > ((< span class = 'number' > 2< / span > , < span class = 'string' > ' o' < / span > )), < span class = 'ident' > char_indices< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > ((< span class = 'number' > 3< / span > , < span class = 'string' > ' d' < / span > )), < span class = 'ident' > char_indices< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > ((< span class = 'number' > 4< / span > , < span class = 'string' > ' b' < / span > )), < span class = 'ident' > char_indices< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > ((< span class = 'number' > 5< / span > , < span class = 'string' > ' y' < / span > )), < span class = 'ident' > char_indices< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > ((< span class = 'number' > 6< / span > , < span class = 'string' > ' e' < / span > )), < span class = 'ident' > char_indices< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > None< / span > , < span class = 'ident' > char_indices< / span > .< span class = 'ident' > next< / span > ());< / pre >
< p > Remember, < a href = "primitive.char.html" > < code > char< / code > < / a > s may not match your human intuition about characters:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > y< / span > < span class = 'op' > =< / span > < span class = 'string' > " y̆" < / span > ;
< span class = 'kw' > let< / span > < span class = 'kw-2' > mut< / span > < span class = 'ident' > char_indices< / span > < span class = 'op' > =< / span > < span class = 'ident' > y< / span > .< span class = 'ident' > char_indices< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > ((< span class = 'number' > 0< / span > , < span class = 'string' > ' y' < / span > )), < span class = 'ident' > char_indices< / span > .< span class = 'ident' > next< / span > ()); < span class = 'comment' > // not (0, ' y̆' )< / span >
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > ((< span class = 'number' > 1< / span > , < span class = 'string' > ' \u{0306}' < / span > )), < span class = 'ident' > char_indices< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > None< / span > , < span class = 'ident' > char_indices< / span > .< span class = 'ident' > next< / span > ());< / pre >
< / div > < h4 id = 'method.bytes' class = 'method' > < code > fn < a href = '#method.bytes' class = 'fnname' > bytes< / a > (& self) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/str/struct.Bytes.html' title = 'core::str::Bytes' > Bytes< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > An iterator over the bytes of a string slice.< / p >
< p > As a string slice consists of a sequence of bytes, we can iterate
through a string slice by byte. This method returns such an iterator.< / p >
< h1 id = 'examples-10' class = 'section-header' > < a href = '#examples-10' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'kw-2' > mut< / span > < span class = 'ident' > bytes< / span > < span class = 'op' > =< / span > < span class = 'string' > " bors" < / span > .< span class = 'ident' > bytes< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > b' b' < / span > ), < span class = 'ident' > bytes< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > b' o' < / span > ), < span class = 'ident' > bytes< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > b' r' < / span > ), < span class = 'ident' > bytes< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > b' s' < / span > ), < span class = 'ident' > bytes< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > None< / span > , < span class = 'ident' > bytes< / span > .< span class = 'ident' > next< / span > ());< / pre >
< / div > < h4 id = 'method.split_whitespace' class = 'method' > < code > fn < a href = '#method.split_whitespace' class = 'fnname' > split_whitespace< / a > (& self) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/rustc_unicode/u_str/struct.SplitWhitespace.html' title = 'rustc_unicode::u_str::SplitWhitespace' > SplitWhitespace< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.1.0' > 1.1.0< / div > < / h4 >
< div class = 'docblock' > < p > Split a string slice by whitespace.< / p >
< p > The iterator returned will return string slices that are sub-slices of
the original string slice, separated by any amount of whitespace.< / p >
< p > ' Whitespace' is defined according to the terms of the Unicode Derived
Core Property < code > White_Space< / code > .< / p >
< h1 id = 'examples-11' class = 'section-header' > < a href = '#examples-11' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'kw-2' > mut< / span > < span class = 'ident' > iter< / span > < span class = 'op' > =< / span > < span class = 'string' > " A few words" < / span > .< span class = 'ident' > split_whitespace< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > " A" < / span > ), < span class = 'ident' > iter< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > " few" < / span > ), < span class = 'ident' > iter< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > " words" < / span > ), < span class = 'ident' > iter< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > None< / span > , < span class = 'ident' > iter< / span > .< span class = 'ident' > next< / span > ());< / pre >
< p > All kinds of whitespace are considered:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'kw-2' > mut< / span > < span class = 'ident' > iter< / span > < span class = 'op' > =< / span > < span class = 'string' > " Mary had\ta\u{2009}little \n\t lamb" < / span > .< span class = 'ident' > split_whitespace< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > " Mary" < / span > ), < span class = 'ident' > iter< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > " had" < / span > ), < span class = 'ident' > iter< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > " a" < / span > ), < span class = 'ident' > iter< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > " little" < / span > ), < span class = 'ident' > iter< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > " lamb" < / span > ), < span class = 'ident' > iter< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > None< / span > , < span class = 'ident' > iter< / span > .< span class = 'ident' > next< / span > ());< / pre >
< / div > < h4 id = 'method.lines' class = 'method' > < code > fn < a href = '#method.lines' class = 'fnname' > lines< / a > (& self) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/str/struct.Lines.html' title = 'core::str::Lines' > Lines< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > An iterator over the lines of a string, as string slices.< / p >
< p > Lines are ended with either a newline (< code > \n< / code > ) or a carriage return with
a line feed (< code > \r\n< / code > ).< / p >
< p > The final line ending is optional.< / p >
< h1 id = 'examples-12' class = 'section-header' > < a href = '#examples-12' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > text< / span > < span class = 'op' > =< / span > < span class = 'string' > " foo\r\nbar\n\nbaz\n" < / span > ;
< span class = 'kw' > let< / span > < span class = 'kw-2' > mut< / span > < span class = 'ident' > lines< / span > < span class = 'op' > =< / span > < span class = 'ident' > text< / span > .< span class = 'ident' > lines< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > " foo" < / span > ), < span class = 'ident' > lines< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > " bar" < / span > ), < span class = 'ident' > lines< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > " " < / span > ), < span class = 'ident' > lines< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > " baz" < / span > ), < span class = 'ident' > lines< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > None< / span > , < span class = 'ident' > lines< / span > .< span class = 'ident' > next< / span > ());< / pre >
< p > The final line ending isn' t required:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > text< / span > < span class = 'op' > =< / span > < span class = 'string' > " foo\nbar\n\r\nbaz" < / span > ;
< span class = 'kw' > let< / span > < span class = 'kw-2' > mut< / span > < span class = 'ident' > lines< / span > < span class = 'op' > =< / span > < span class = 'ident' > text< / span > .< span class = 'ident' > lines< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > " foo" < / span > ), < span class = 'ident' > lines< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > " bar" < / span > ), < span class = 'ident' > lines< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > " " < / span > ), < span class = 'ident' > lines< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > " baz" < / span > ), < span class = 'ident' > lines< / span > .< span class = 'ident' > next< / span > ());
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > None< / span > , < span class = 'ident' > lines< / span > .< span class = 'ident' > next< / span > ());< / pre >
< / div > < h4 id = 'method.lines_any' class = 'method' > < code > fn < a href = '#method.lines_any' class = 'fnname' > lines_any< / a > (& self) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/str/struct.LinesAny.html' title = 'core::str::LinesAny' > LinesAny< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'stability' > < em class = 'stab deprecated' > Deprecated since 1.4.0< p > : use lines() instead now< / p >
< / em > < / div > < div class = 'docblock' > < p > An iterator over the lines of a string.< / p >
< / div > < h4 id = 'method.encode_utf16' class = 'method' > < code > fn < a href = '#method.encode_utf16' class = 'fnname' > encode_utf16< / a > (& self) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/collections/str/struct.EncodeUtf16.html' title = 'collections::str::EncodeUtf16' > EncodeUtf16< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.8.0' > 1.8.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns an iterator of < code > u16< / code > over the string encoded as UTF-16.< / p >
< / div > < h4 id = 'method.contains' class = 'method' > < code > fn < a href = '#method.contains' class = 'fnname' > contains< / a > < 'a, P> (& 'a self, pat: P) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.bool.html' > bool< / a > < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns < code > true< / code > if the given pattern matches a sub-slice of
this string slice.< / p >
< p > Returns < code > false< / code > if it does not.< / p >
< h1 id = 'examples-13' class = 'section-header' > < a href = '#examples-13' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > bananas< / span > < span class = 'op' > =< / span > < span class = 'string' > " bananas" < / span > ;
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > bananas< / span > .< span class = 'ident' > contains< / span > (< span class = 'string' > " nana" < / span > ));
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'op' > !< / span > < span class = 'ident' > bananas< / span > .< span class = 'ident' > contains< / span > (< span class = 'string' > " apples" < / span > ));< / pre >
< / div > < h4 id = 'method.starts_with' class = 'method' > < code > fn < a href = '#method.starts_with' class = 'fnname' > starts_with< / a > < 'a, P> (& 'a self, pat: P) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.bool.html' > bool< / a > < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns < code > true< / code > if the given pattern matches a prefix of this
string slice.< / p >
< p > Returns < code > false< / code > if it does not.< / p >
< h1 id = 'examples-14' class = 'section-header' > < a href = '#examples-14' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > bananas< / span > < span class = 'op' > =< / span > < span class = 'string' > " bananas" < / span > ;
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > bananas< / span > .< span class = 'ident' > starts_with< / span > (< span class = 'string' > " bana" < / span > ));
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'op' > !< / span > < span class = 'ident' > bananas< / span > .< span class = 'ident' > starts_with< / span > (< span class = 'string' > " nana" < / span > ));< / pre >
< / div > < h4 id = 'method.ends_with' class = 'method' > < code > fn < a href = '#method.ends_with' class = 'fnname' > ends_with< / a > < 'a, P> (& 'a self, pat: P) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.bool.html' > bool< / a > < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> , P::< a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Searcher< / a > : < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.ReverseSearcher.html' title = 'core::str::pattern::ReverseSearcher' > ReverseSearcher< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns < code > true< / code > if the given pattern matches a suffix of this
string slice.< / p >
< p > Returns < code > false< / code > if it does not.< / p >
< h1 id = 'examples-15' class = 'section-header' > < a href = '#examples-15' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > bananas< / span > < span class = 'op' > =< / span > < span class = 'string' > " bananas" < / span > ;
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > bananas< / span > .< span class = 'ident' > ends_with< / span > (< span class = 'string' > " anas" < / span > ));
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'op' > !< / span > < span class = 'ident' > bananas< / span > .< span class = 'ident' > ends_with< / span > (< span class = 'string' > " nana" < / span > ));< / pre >
< / div > < h4 id = 'method.find' class = 'method' > < code > fn < a href = '#method.find' class = 'fnname' > find< / a > < 'a, P> (& 'a self, pat: P) -> < a class = 'enum' href = 'https://doc.rust-lang.org/nightly/core/option/enum.Option.html' title = 'core::option::Option' > Option< / a > < < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.usize.html' > usize< / a > > < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns the byte index of the first character of this string slice that
matches the pattern.< / p >
< p > Returns < a href = "option/enum.Option.html#variant.None" > < code > None< / code > < / a > if the pattern doesn' t match.< / p >
< p > The pattern can be a < code > & str< / code > , < a href = "primitive.char.html" > < code > char< / code > < / a > , or a closure that determines if
a character matches.< / p >
< h1 id = 'examples-16' class = 'section-header' > < a href = '#examples-16' > Examples< / a > < / h1 >
< p > Simple patterns:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " Löwe 老虎 Léopard" < / span > ;
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > s< / span > .< span class = 'ident' > find< / span > (< span class = 'string' > ' L' < / span > ), < span class = 'prelude-val' > Some< / span > (< span class = 'number' > 0< / span > ));
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > s< / span > .< span class = 'ident' > find< / span > (< span class = 'string' > ' é' < / span > ), < span class = 'prelude-val' > Some< / span > (< span class = 'number' > 14< / span > ));
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > s< / span > .< span class = 'ident' > find< / span > (< span class = 'string' > " Léopard" < / span > ), < span class = 'prelude-val' > Some< / span > (< span class = 'number' > 13< / span > ));< / pre >
< p > More complex patterns with closures:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " Löwe 老虎 Léopard" < / span > ;
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > s< / span > .< span class = 'ident' > find< / span > (< span class = 'ident' > char< / span > ::< span class = 'ident' > is_whitespace< / span > ), < span class = 'prelude-val' > Some< / span > (< span class = 'number' > 5< / span > ));
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > s< / span > .< span class = 'ident' > find< / span > (< span class = 'ident' > char< / span > ::< span class = 'ident' > is_lowercase< / span > ), < span class = 'prelude-val' > Some< / span > (< span class = 'number' > 1< / span > ));< / pre >
< p > Not finding the pattern:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " Löwe 老虎 Léopard" < / span > ;
< span class = 'kw' > let< / span > < span class = 'ident' > x< / span > : < span class = 'kw-2' > & < / span > [_] < span class = 'op' > =< / span > < span class = 'kw-2' > & < / span > [< span class = 'string' > ' 1' < / span > , < span class = 'string' > ' 2' < / span > ];
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > s< / span > .< span class = 'ident' > find< / span > (< span class = 'ident' > x< / span > ), < span class = 'prelude-val' > None< / span > );< / pre >
< / div > < h4 id = 'method.rfind' class = 'method' > < code > fn < a href = '#method.rfind' class = 'fnname' > rfind< / a > < 'a, P> (& 'a self, pat: P) -> < a class = 'enum' href = 'https://doc.rust-lang.org/nightly/core/option/enum.Option.html' title = 'core::option::Option' > Option< / a > < < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.usize.html' > usize< / a > > < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> , P::< a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Searcher< / a > : < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.ReverseSearcher.html' title = 'core::str::pattern::ReverseSearcher' > ReverseSearcher< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns the byte index of the last character of this string slice that
matches the pattern.< / p >
< p > Returns < a href = "option/enum.Option.html#variant.None" > < code > None< / code > < / a > if the pattern doesn' t match.< / p >
< p > The pattern can be a < code > & str< / code > , < a href = "primitive.char.html" > < code > char< / code > < / a > , or a closure that determines if
a character matches.< / p >
< h1 id = 'examples-17' class = 'section-header' > < a href = '#examples-17' > Examples< / a > < / h1 >
< p > Simple patterns:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " Löwe 老虎 Léopard" < / span > ;
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > s< / span > .< span class = 'ident' > rfind< / span > (< span class = 'string' > ' L' < / span > ), < span class = 'prelude-val' > Some< / span > (< span class = 'number' > 13< / span > ));
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > s< / span > .< span class = 'ident' > rfind< / span > (< span class = 'string' > ' é' < / span > ), < span class = 'prelude-val' > Some< / span > (< span class = 'number' > 14< / span > ));< / pre >
< p > More complex patterns with closures:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " Löwe 老虎 Léopard" < / span > ;
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > s< / span > .< span class = 'ident' > rfind< / span > (< span class = 'ident' > char< / span > ::< span class = 'ident' > is_whitespace< / span > ), < span class = 'prelude-val' > Some< / span > (< span class = 'number' > 12< / span > ));
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > s< / span > .< span class = 'ident' > rfind< / span > (< span class = 'ident' > char< / span > ::< span class = 'ident' > is_lowercase< / span > ), < span class = 'prelude-val' > Some< / span > (< span class = 'number' > 20< / span > ));< / pre >
< p > Not finding the pattern:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " Löwe 老虎 Léopard" < / span > ;
< span class = 'kw' > let< / span > < span class = 'ident' > x< / span > : < span class = 'kw-2' > & < / span > [_] < span class = 'op' > =< / span > < span class = 'kw-2' > & < / span > [< span class = 'string' > ' 1' < / span > , < span class = 'string' > ' 2' < / span > ];
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > s< / span > .< span class = 'ident' > rfind< / span > (< span class = 'ident' > x< / span > ), < span class = 'prelude-val' > None< / span > );< / pre >
< / div > < h4 id = 'method.split' class = 'method' > < code > fn < a href = '#method.split' class = 'fnname' > split< / a > < 'a, P> (& 'a self, pat: P) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/str/struct.Split.html' title = 'core::str::Split' > Split< / a > < 'a, P> < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > An iterator over substrings of this string slice, separated by
characters matched by a pattern.< / p >
< p > The pattern can be a < code > & str< / code > , < a href = "primitive.char.html" > < code > char< / code > < / a > , or a closure that determines the
split.< / p >
< h1 id = 'iterator-behavior' class = 'section-header' > < a href = '#iterator-behavior' > Iterator behavior< / a > < / h1 >
< p > The returned iterator will be a < a href = "iter/trait.DoubleEndedIterator.html" > < code > DoubleEndedIterator< / code > < / a > if the pattern
allows a reverse search and forward/reverse search yields the same
elements. This is true for, eg, < a href = "primitive.char.html" > < code > char< / code > < / a > but not for < code > & str< / code > .< / p >
< p > If the pattern allows a reverse search but its results might differ
from a forward search, the < a href = "#method.rsplit" > < code > rsplit()< / code > < / a > method can be used.< / p >
< h1 id = 'examples-18' class = 'section-header' > < a href = '#examples-18' > Examples< / a > < / h1 >
< p > Simple patterns:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " Mary had a little lamb" < / span > .< span class = 'ident' > split< / span > (< span class = 'string' > ' ' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " Mary" < / span > , < span class = 'string' > " had" < / span > , < span class = 'string' > " a" < / span > , < span class = 'string' > " little" < / span > , < span class = 'string' > " lamb" < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " " < / span > .< span class = 'ident' > split< / span > (< span class = 'string' > ' X' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " " < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " lionXXtigerXleopard" < / span > .< span class = 'ident' > split< / span > (< span class = 'string' > ' X' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " lion" < / span > , < span class = 'string' > " " < / span > , < span class = 'string' > " tiger" < / span > , < span class = 'string' > " leopard" < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " lion::tiger::leopard" < / span > .< span class = 'ident' > split< / span > (< span class = 'string' > " ::" < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " lion" < / span > , < span class = 'string' > " tiger" < / span > , < span class = 'string' > " leopard" < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " abc1def2ghi" < / span > .< span class = 'ident' > split< / span > (< span class = 'ident' > char< / span > ::< span class = 'ident' > is_numeric< / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " abc" < / span > , < span class = 'string' > " def" < / span > , < span class = 'string' > " ghi" < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " lionXtigerXleopard" < / span > .< span class = 'ident' > split< / span > (< span class = 'ident' > char< / span > ::< span class = 'ident' > is_uppercase< / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " lion" < / span > , < span class = 'string' > " tiger" < / span > , < span class = 'string' > " leopard" < / span > ]);< / pre >
< p > A more complex pattern, using a closure:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " abc1defXghi" < / span > .< span class = 'ident' > split< / span > (< span class = 'op' > |< / span > < span class = 'ident' > c< / span > < span class = 'op' > |< / span > < span class = 'ident' > c< / span > < span class = 'op' > ==< / span > < span class = 'string' > ' 1' < / span > < span class = 'op' > ||< / span > < span class = 'ident' > c< / span > < span class = 'op' > ==< / span > < span class = 'string' > ' X' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " abc" < / span > , < span class = 'string' > " def" < / span > , < span class = 'string' > " ghi" < / span > ]);< / pre >
< p > If a string contains multiple contiguous separators, you will end up
with empty strings in the output:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > x< / span > < span class = 'op' > =< / span > < span class = 'string' > " ||||a||b|c" < / span > .< span class = 'ident' > to_string< / span > ();
< span class = 'kw' > let< / span > < span class = 'ident' > d< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > _< span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'ident' > x< / span > .< span class = 'ident' > split< / span > (< span class = 'string' > ' |' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > d< / span > , < span class = 'kw-2' > & < / span > [< span class = 'string' > " " < / span > , < span class = 'string' > " " < / span > , < span class = 'string' > " " < / span > , < span class = 'string' > " " < / span > , < span class = 'string' > " a" < / span > , < span class = 'string' > " " < / span > , < span class = 'string' > " b" < / span > , < span class = 'string' > " c" < / span > ]);< / pre >
< p > Contiguous separators are separated by the empty string.< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > x< / span > < span class = 'op' > =< / span > < span class = 'string' > " (///)" < / span > .< span class = 'ident' > to_string< / span > ();
< span class = 'kw' > let< / span > < span class = 'ident' > d< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > _< span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'ident' > x< / span > .< span class = 'ident' > split< / span > (< span class = 'string' > ' /' < / span > ).< span class = 'ident' > collect< / span > ();;
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > d< / span > , < span class = 'kw-2' > & < / span > [< span class = 'string' > " (" < / span > , < span class = 'string' > " " < / span > , < span class = 'string' > " " < / span > , < span class = 'string' > " )" < / span > ]);< / pre >
< p > Separators at the start or end of a string are neighbored
by empty strings.< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > d< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > _< span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " 010" < / span > .< span class = 'ident' > split< / span > (< span class = 'string' > " 0" < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > d< / span > , < span class = 'kw-2' > & < / span > [< span class = 'string' > " " < / span > , < span class = 'string' > " 1" < / span > , < span class = 'string' > " " < / span > ]);< / pre >
< p > When the empty string is used as a separator, it separates
every character in the string, along with the beginning
and end of the string.< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > f< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > _< span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " rust" < / span > .< span class = 'ident' > split< / span > (< span class = 'string' > " " < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > f< / span > , < span class = 'kw-2' > & < / span > [< span class = 'string' > " " < / span > , < span class = 'string' > " r" < / span > , < span class = 'string' > " u" < / span > , < span class = 'string' > " s" < / span > , < span class = 'string' > " t" < / span > , < span class = 'string' > " " < / span > ]);< / pre >
< p > Contiguous separators can lead to possibly surprising behavior
when whitespace is used as the separator. This code is correct:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > x< / span > < span class = 'op' > =< / span > < span class = 'string' > " a b c" < / span > .< span class = 'ident' > to_string< / span > ();
< span class = 'kw' > let< / span > < span class = 'ident' > d< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > _< span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'ident' > x< / span > .< span class = 'ident' > split< / span > (< span class = 'string' > ' ' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > d< / span > , < span class = 'kw-2' > & < / span > [< span class = 'string' > " " < / span > , < span class = 'string' > " " < / span > , < span class = 'string' > " " < / span > , < span class = 'string' > " " < / span > , < span class = 'string' > " a" < / span > , < span class = 'string' > " " < / span > , < span class = 'string' > " b" < / span > , < span class = 'string' > " c" < / span > ]);< / pre >
< p > It does < em > not< / em > give you:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > d< / span > , < span class = 'kw-2' > & < / span > [< span class = 'string' > " a" < / span > , < span class = 'string' > " b" < / span > , < span class = 'string' > " c" < / span > ]);< / pre >
< p > Use < a href = "#method.split_whitespace" > < code > split_whitespace()< / code > < / a > for this behavior.< / p >
< / div > < h4 id = 'method.rsplit' class = 'method' > < code > fn < a href = '#method.rsplit' class = 'fnname' > rsplit< / a > < 'a, P> (& 'a self, pat: P) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/str/struct.RSplit.html' title = 'core::str::RSplit' > RSplit< / a > < 'a, P> < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> , P::< a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Searcher< / a > : < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.ReverseSearcher.html' title = 'core::str::pattern::ReverseSearcher' > ReverseSearcher< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > An iterator over substrings of the given string slice, separated by
characters matched by a pattern and yielded in reverse order.< / p >
< p > The pattern can be a < code > & str< / code > , < a href = "primitive.char.html" > < code > char< / code > < / a > , or a closure that determines the
split.< / p >
< h1 id = 'iterator-behavior-1' class = 'section-header' > < a href = '#iterator-behavior-1' > Iterator behavior< / a > < / h1 >
< p > The returned iterator requires that the pattern supports a reverse
search, and it will be a < a href = "iter/trait.DoubleEndedIterator.html" > < code > DoubleEndedIterator< / code > < / a > if a forward/reverse
search yields the same elements.< / p >
< p > For iterating from the front, the < a href = "#method.split" > < code > split()< / code > < / a > method can be used.< / p >
< h1 id = 'examples-19' class = 'section-header' > < a href = '#examples-19' > Examples< / a > < / h1 >
< p > Simple patterns:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " Mary had a little lamb" < / span > .< span class = 'ident' > rsplit< / span > (< span class = 'string' > ' ' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " lamb" < / span > , < span class = 'string' > " little" < / span > , < span class = 'string' > " a" < / span > , < span class = 'string' > " had" < / span > , < span class = 'string' > " Mary" < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " " < / span > .< span class = 'ident' > rsplit< / span > (< span class = 'string' > ' X' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " " < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " lionXXtigerXleopard" < / span > .< span class = 'ident' > rsplit< / span > (< span class = 'string' > ' X' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " leopard" < / span > , < span class = 'string' > " tiger" < / span > , < span class = 'string' > " " < / span > , < span class = 'string' > " lion" < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " lion::tiger::leopard" < / span > .< span class = 'ident' > rsplit< / span > (< span class = 'string' > " ::" < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " leopard" < / span > , < span class = 'string' > " tiger" < / span > , < span class = 'string' > " lion" < / span > ]);< / pre >
< p > A more complex pattern, using a closure:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " abc1defXghi" < / span > .< span class = 'ident' > rsplit< / span > (< span class = 'op' > |< / span > < span class = 'ident' > c< / span > < span class = 'op' > |< / span > < span class = 'ident' > c< / span > < span class = 'op' > ==< / span > < span class = 'string' > ' 1' < / span > < span class = 'op' > ||< / span > < span class = 'ident' > c< / span > < span class = 'op' > ==< / span > < span class = 'string' > ' X' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " ghi" < / span > , < span class = 'string' > " def" < / span > , < span class = 'string' > " abc" < / span > ]);< / pre >
< / div > < h4 id = 'method.split_terminator' class = 'method' > < code > fn < a href = '#method.split_terminator' class = 'fnname' > split_terminator< / a > < 'a, P> (& 'a self, pat: P) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/str/struct.SplitTerminator.html' title = 'core::str::SplitTerminator' > SplitTerminator< / a > < 'a, P> < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > An iterator over substrings of the given string slice, separated by
characters matched by a pattern.< / p >
< p > The pattern can be a < code > & str< / code > , < a href = "primitive.char.html" > < code > char< / code > < / a > , or a closure that determines the
split.< / p >
< p > Equivalent to < a href = "#method.split" > < code > split()< / code > < / a > , except that the trailing substring
is skipped if empty.< / p >
< p > This method can be used for string data that is < em > terminated< / em > ,
rather than < em > separated< / em > by a pattern.< / p >
< h1 id = 'iterator-behavior-2' class = 'section-header' > < a href = '#iterator-behavior-2' > Iterator behavior< / a > < / h1 >
< p > The returned iterator will be a < a href = "iter/trait.DoubleEndedIterator.html" > < code > DoubleEndedIterator< / code > < / a > if the pattern
allows a reverse search and forward/reverse search yields the same
elements. This is true for, eg, < a href = "primitive.char.html" > < code > char< / code > < / a > but not for < code > & str< / code > .< / p >
< p > If the pattern allows a reverse search but its results might differ
from a forward search, the < a href = "#method.rsplit_terminator" > < code > rsplit_terminator()< / code > < / a > method can be used.< / p >
< h1 id = 'examples-20' class = 'section-header' > < a href = '#examples-20' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " A.B." < / span > .< span class = 'ident' > split_terminator< / span > (< span class = 'string' > ' .' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " A" < / span > , < span class = 'string' > " B" < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " A..B.." < / span > .< span class = 'ident' > split_terminator< / span > (< span class = 'string' > " ." < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " A" < / span > , < span class = 'string' > " " < / span > , < span class = 'string' > " B" < / span > , < span class = 'string' > " " < / span > ]);< / pre >
< / div > < h4 id = 'method.rsplit_terminator' class = 'method' > < code > fn < a href = '#method.rsplit_terminator' class = 'fnname' > rsplit_terminator< / a > < 'a, P> (& 'a self, pat: P) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/str/struct.RSplitTerminator.html' title = 'core::str::RSplitTerminator' > RSplitTerminator< / a > < 'a, P> < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> , P::< a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Searcher< / a > : < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.ReverseSearcher.html' title = 'core::str::pattern::ReverseSearcher' > ReverseSearcher< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > An iterator over substrings of < code > self< / code > , separated by characters
matched by a pattern and yielded in reverse order.< / p >
< p > The pattern can be a simple < code > & str< / code > , < a href = "primitive.char.html" > < code > char< / code > < / a > , or a closure that
determines the split.
Additional libraries might provide more complex patterns like
regular expressions.< / p >
< p > Equivalent to < a href = "#method.split" > < code > split()< / code > < / a > , except that the trailing substring is
skipped if empty.< / p >
< p > This method can be used for string data that is < em > terminated< / em > ,
rather than < em > separated< / em > by a pattern.< / p >
< h1 id = 'iterator-behavior-3' class = 'section-header' > < a href = '#iterator-behavior-3' > Iterator behavior< / a > < / h1 >
< p > The returned iterator requires that the pattern supports a
reverse search, and it will be double ended if a forward/reverse
search yields the same elements.< / p >
< p > For iterating from the front, the < a href = "#method.split_terminator" > < code > split_terminator()< / code > < / a > method can be
used.< / p >
< h1 id = 'examples-21' class = 'section-header' > < a href = '#examples-21' > Examples< / a > < / h1 >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " A.B." < / span > .< span class = 'ident' > rsplit_terminator< / span > (< span class = 'string' > ' .' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " B" < / span > , < span class = 'string' > " A" < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " A..B.." < / span > .< span class = 'ident' > rsplit_terminator< / span > (< span class = 'string' > " ." < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " " < / span > , < span class = 'string' > " B" < / span > , < span class = 'string' > " " < / span > , < span class = 'string' > " A" < / span > ]);< / pre >
< / div > < h4 id = 'method.splitn' class = 'method' > < code > fn < a href = '#method.splitn' class = 'fnname' > splitn< / a > < 'a, P> (& 'a self, count: < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.usize.html' > usize< / a > , pat: P) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/str/struct.SplitN.html' title = 'core::str::SplitN' > SplitN< / a > < 'a, P> < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > An iterator over substrings of the given string slice, separated by a
pattern, restricted to returning at most < code > count< / code > items.< / p >
< p > The last element returned, if any, will contain the remainder of the
string slice.< / p >
< p > The pattern can be a < code > & str< / code > , < a href = "primitive.char.html" > < code > char< / code > < / a > , or a closure that determines the
split.< / p >
< h1 id = 'iterator-behavior-4' class = 'section-header' > < a href = '#iterator-behavior-4' > Iterator behavior< / a > < / h1 >
< p > The returned iterator will not be double ended, because it is
not efficient to support.< / p >
< p > If the pattern allows a reverse search, the < a href = "#method.rsplitn" > < code > rsplitn()< / code > < / a > method can be
used.< / p >
< h1 id = 'examples-22' class = 'section-header' > < a href = '#examples-22' > Examples< / a > < / h1 >
< p > Simple patterns:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " Mary had a little lambda" < / span > .< span class = 'ident' > splitn< / span > (< span class = 'number' > 3< / span > , < span class = 'string' > ' ' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " Mary" < / span > , < span class = 'string' > " had" < / span > , < span class = 'string' > " a little lambda" < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " lionXXtigerXleopard" < / span > .< span class = 'ident' > splitn< / span > (< span class = 'number' > 3< / span > , < span class = 'string' > " X" < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " lion" < / span > , < span class = 'string' > " " < / span > , < span class = 'string' > " tigerXleopard" < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " abcXdef" < / span > .< span class = 'ident' > splitn< / span > (< span class = 'number' > 1< / span > , < span class = 'string' > ' X' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " abcXdef" < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " " < / span > .< span class = 'ident' > splitn< / span > (< span class = 'number' > 1< / span > , < span class = 'string' > ' X' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " " < / span > ]);< / pre >
< p > A more complex pattern, using a closure:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " abc1defXghi" < / span > .< span class = 'ident' > splitn< / span > (< span class = 'number' > 2< / span > , < span class = 'op' > |< / span > < span class = 'ident' > c< / span > < span class = 'op' > |< / span > < span class = 'ident' > c< / span > < span class = 'op' > ==< / span > < span class = 'string' > ' 1' < / span > < span class = 'op' > ||< / span > < span class = 'ident' > c< / span > < span class = 'op' > ==< / span > < span class = 'string' > ' X' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " abc" < / span > , < span class = 'string' > " defXghi" < / span > ]);< / pre >
< / div > < h4 id = 'method.rsplitn' class = 'method' > < code > fn < a href = '#method.rsplitn' class = 'fnname' > rsplitn< / a > < 'a, P> (& 'a self, count: < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.usize.html' > usize< / a > , pat: P) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/str/struct.RSplitN.html' title = 'core::str::RSplitN' > RSplitN< / a > < 'a, P> < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> , P::< a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Searcher< / a > : < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.ReverseSearcher.html' title = 'core::str::pattern::ReverseSearcher' > ReverseSearcher< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > An iterator over substrings of this string slice, separated by a
pattern, starting from the end of the string, restricted to returning
at most < code > count< / code > items.< / p >
< p > The last element returned, if any, will contain the remainder of the
string slice.< / p >
< p > The pattern can be a < code > & str< / code > , < a href = "primitive.char.html" > < code > char< / code > < / a > , or a closure that
determines the split.< / p >
< h1 id = 'iterator-behavior-5' class = 'section-header' > < a href = '#iterator-behavior-5' > Iterator behavior< / a > < / h1 >
< p > The returned iterator will not be double ended, because it is not
efficient to support.< / p >
< p > For splitting from the front, the < a href = "#method.splitn" > < code > splitn()< / code > < / a > method can be used.< / p >
< h1 id = 'examples-23' class = 'section-header' > < a href = '#examples-23' > Examples< / a > < / h1 >
< p > Simple patterns:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " Mary had a little lamb" < / span > .< span class = 'ident' > rsplitn< / span > (< span class = 'number' > 3< / span > , < span class = 'string' > ' ' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " lamb" < / span > , < span class = 'string' > " little" < / span > , < span class = 'string' > " Mary had a" < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " lionXXtigerXleopard" < / span > .< span class = 'ident' > rsplitn< / span > (< span class = 'number' > 3< / span > , < span class = 'string' > ' X' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " leopard" < / span > , < span class = 'string' > " tiger" < / span > , < span class = 'string' > " lionX" < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " lion::tiger::leopard" < / span > .< span class = 'ident' > rsplitn< / span > (< span class = 'number' > 2< / span > , < span class = 'string' > " ::" < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " leopard" < / span > , < span class = 'string' > " lion::tiger" < / span > ]);< / pre >
< p > A more complex pattern, using a closure:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " abc1defXghi" < / span > .< span class = 'ident' > rsplitn< / span > (< span class = 'number' > 2< / span > , < span class = 'op' > |< / span > < span class = 'ident' > c< / span > < span class = 'op' > |< / span > < span class = 'ident' > c< / span > < span class = 'op' > ==< / span > < span class = 'string' > ' 1' < / span > < span class = 'op' > ||< / span > < span class = 'ident' > c< / span > < span class = 'op' > ==< / span > < span class = 'string' > ' X' < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " ghi" < / span > , < span class = 'string' > " abc1def" < / span > ]);< / pre >
< / div > < h4 id = 'method.matches' class = 'method' > < code > fn < a href = '#method.matches' class = 'fnname' > matches< / a > < 'a, P> (& 'a self, pat: P) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/str/struct.Matches.html' title = 'core::str::Matches' > Matches< / a > < 'a, P> < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.2.0' > 1.2.0< / div > < / h4 >
< div class = 'docblock' > < p > An iterator over the matches of a pattern within the given string
slice.< / p >
< p > The pattern can be a < code > & str< / code > , < a href = "primitive.char.html" > < code > char< / code > < / a > , or a closure that
determines if a character matches.< / p >
< h1 id = 'iterator-behavior-6' class = 'section-header' > < a href = '#iterator-behavior-6' > Iterator behavior< / a > < / h1 >
< p > The returned iterator will be a < a href = "iter/trait.DoubleEndedIterator.html" > < code > DoubleEndedIterator< / code > < / a > if the pattern
allows a reverse search and forward/reverse search yields the same
elements. This is true for, eg, < a href = "primitive.char.html" > < code > char< / code > < / a > but not for < code > & str< / code > .< / p >
< p > If the pattern allows a reverse search but its results might differ
from a forward search, the < a href = "#method.rmatches" > < code > rmatches()< / code > < / a > method can be used.< / p >
< h1 id = 'examples-24' class = 'section-header' > < a href = '#examples-24' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " abcXXXabcYYYabc" < / span > .< span class = 'ident' > matches< / span > (< span class = 'string' > " abc" < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " abc" < / span > , < span class = 'string' > " abc" < / span > , < span class = 'string' > " abc" < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " 1abc2abc3" < / span > .< span class = 'ident' > matches< / span > (< span class = 'ident' > char< / span > ::< span class = 'ident' > is_numeric< / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " 1" < / span > , < span class = 'string' > " 2" < / span > , < span class = 'string' > " 3" < / span > ]);< / pre >
< / div > < h4 id = 'method.rmatches' class = 'method' > < code > fn < a href = '#method.rmatches' class = 'fnname' > rmatches< / a > < 'a, P> (& 'a self, pat: P) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/str/struct.RMatches.html' title = 'core::str::RMatches' > RMatches< / a > < 'a, P> < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> , P::< a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Searcher< / a > : < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.ReverseSearcher.html' title = 'core::str::pattern::ReverseSearcher' > ReverseSearcher< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.2.0' > 1.2.0< / div > < / h4 >
< div class = 'docblock' > < p > An iterator over the matches of a pattern within this string slice,
yielded in reverse order.< / p >
< p > The pattern can be a < code > & str< / code > , < a href = "primitive.char.html" > < code > char< / code > < / a > , or a closure that determines if
a character matches.< / p >
< h1 id = 'iterator-behavior-7' class = 'section-header' > < a href = '#iterator-behavior-7' > Iterator behavior< / a > < / h1 >
< p > The returned iterator requires that the pattern supports a reverse
search, and it will be a < a href = "iter/trait.DoubleEndedIterator.html" > < code > DoubleEndedIterator< / code > < / a > if a forward/reverse
search yields the same elements.< / p >
< p > For iterating from the front, the < a href = "#method.matches" > < code > matches()< / code > < / a > method can be used.< / p >
< h1 id = 'examples-25' class = 'section-header' > < a href = '#examples-25' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " abcXXXabcYYYabc" < / span > .< span class = 'ident' > rmatches< / span > (< span class = 'string' > " abc" < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " abc" < / span > , < span class = 'string' > " abc" < / span > , < span class = 'string' > " abc" < / span > ]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > < span class = 'kw-2' > & < / span > < span class = 'ident' > str< / span > < span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " 1abc2abc3" < / span > .< span class = 'ident' > rmatches< / span > (< span class = 'ident' > char< / span > ::< span class = 'ident' > is_numeric< / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [< span class = 'string' > " 3" < / span > , < span class = 'string' > " 2" < / span > , < span class = 'string' > " 1" < / span > ]);< / pre >
< / div > < h4 id = 'method.match_indices' class = 'method' > < code > fn < a href = '#method.match_indices' class = 'fnname' > match_indices< / a > < 'a, P> (& 'a self, pat: P) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/str/struct.MatchIndices.html' title = 'core::str::MatchIndices' > MatchIndices< / a > < 'a, P> < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.5.0' > 1.5.0< / div > < / h4 >
< div class = 'docblock' > < p > An iterator over the disjoint matches of a pattern within this string
slice as well as the index that the match starts at.< / p >
< p > For matches of < code > pat< / code > within < code > self< / code > that overlap, only the indices
corresponding to the first match are returned.< / p >
< p > The pattern can be a < code > & str< / code > , < a href = "primitive.char.html" > < code > char< / code > < / a > , or a closure that determines
if a character matches.< / p >
< h1 id = 'iterator-behavior-8' class = 'section-header' > < a href = '#iterator-behavior-8' > Iterator behavior< / a > < / h1 >
< p > The returned iterator will be a < a href = "iter/trait.DoubleEndedIterator.html" > < code > DoubleEndedIterator< / code > < / a > if the pattern
allows a reverse search and forward/reverse search yields the same
elements. This is true for, eg, < a href = "primitive.char.html" > < code > char< / code > < / a > but not for < code > & str< / code > .< / p >
< p > If the pattern allows a reverse search but its results might differ
from a forward search, the < a href = "#method.rmatch_indices" > < code > rmatch_indices()< / code > < / a > method can be used.< / p >
< h1 id = 'examples-26' class = 'section-header' > < a href = '#examples-26' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > _< span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " abcXXXabcYYYabc" < / span > .< span class = 'ident' > match_indices< / span > (< span class = 'string' > " abc" < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [(< span class = 'number' > 0< / span > , < span class = 'string' > " abc" < / span > ), (< span class = 'number' > 6< / span > , < span class = 'string' > " abc" < / span > ), (< span class = 'number' > 12< / span > , < span class = 'string' > " abc" < / span > )]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > _< span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " 1abcabc2" < / span > .< span class = 'ident' > match_indices< / span > (< span class = 'string' > " abc" < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [(< span class = 'number' > 1< / span > , < span class = 'string' > " abc" < / span > ), (< span class = 'number' > 4< / span > , < span class = 'string' > " abc" < / span > )]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > _< span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " ababa" < / span > .< span class = 'ident' > match_indices< / span > (< span class = 'string' > " aba" < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [(< span class = 'number' > 0< / span > , < span class = 'string' > " aba" < / span > )]); < span class = 'comment' > // only the first `aba`< / span > < / pre >
< / div > < h4 id = 'method.rmatch_indices' class = 'method' > < code > fn < a href = '#method.rmatch_indices' class = 'fnname' > rmatch_indices< / a > < 'a, P> (& 'a self, pat: P) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/str/struct.RMatchIndices.html' title = 'core::str::RMatchIndices' > RMatchIndices< / a > < 'a, P> < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> , P::< a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Searcher< / a > : < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.ReverseSearcher.html' title = 'core::str::pattern::ReverseSearcher' > ReverseSearcher< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.5.0' > 1.5.0< / div > < / h4 >
< div class = 'docblock' > < p > An iterator over the disjoint matches of a pattern within < code > self< / code > ,
yielded in reverse order along with the index of the match.< / p >
< p > For matches of < code > pat< / code > within < code > self< / code > that overlap, only the indices
corresponding to the last match are returned.< / p >
< p > The pattern can be a < code > & str< / code > , < a href = "primitive.char.html" > < code > char< / code > < / a > , or a closure that determines if a
character matches.< / p >
< h1 id = 'iterator-behavior-9' class = 'section-header' > < a href = '#iterator-behavior-9' > Iterator behavior< / a > < / h1 >
< p > The returned iterator requires that the pattern supports a reverse
search, and it will be a < a href = "iter/trait.DoubleEndedIterator.html" > < code > DoubleEndedIterator< / code > < / a > if a forward/reverse
search yields the same elements.< / p >
< p > For iterating from the front, the < a href = "#method.match_indices" > < code > match_indices()< / code > < / a > method can be used.< / p >
< h1 id = 'examples-27' class = 'section-header' > < a href = '#examples-27' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > _< span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " abcXXXabcYYYabc" < / span > .< span class = 'ident' > rmatch_indices< / span > (< span class = 'string' > " abc" < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [(< span class = 'number' > 12< / span > , < span class = 'string' > " abc" < / span > ), (< span class = 'number' > 6< / span > , < span class = 'string' > " abc" < / span > ), (< span class = 'number' > 0< / span > , < span class = 'string' > " abc" < / span > )]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > _< span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " 1abcabc2" < / span > .< span class = 'ident' > rmatch_indices< / span > (< span class = 'string' > " abc" < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [(< span class = 'number' > 4< / span > , < span class = 'string' > " abc" < / span > ), (< span class = 'number' > 1< / span > , < span class = 'string' > " abc" < / span > )]);
< span class = 'kw' > let< / span > < span class = 'ident' > v< / span > : < span class = 'ident' > Vec< / span > < span class = 'op' > < < / span > _< span class = 'op' > > < / span > < span class = 'op' > =< / span > < span class = 'string' > " ababa" < / span > .< span class = 'ident' > rmatch_indices< / span > (< span class = 'string' > " aba" < / span > ).< span class = 'ident' > collect< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > v< / span > , [(< span class = 'number' > 2< / span > , < span class = 'string' > " aba" < / span > )]); < span class = 'comment' > // only the last `aba`< / span > < / pre >
< / div > < h4 id = 'method.trim' class = 'method' > < code > fn < a href = '#method.trim' class = 'fnname' > trim< / a > (& self) -> & < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns a string slice with leading and trailing whitespace removed.< / p >
< p > ' Whitespace' is defined according to the terms of the Unicode Derived
Core Property < code > White_Space< / code > .< / p >
< h1 id = 'examples-28' class = 'section-header' > < a href = '#examples-28' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " Hello\tworld\t" < / span > ;
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " Hello\tworld" < / span > , < span class = 'ident' > s< / span > .< span class = 'ident' > trim< / span > ());< / pre >
< / div > < h4 id = 'method.trim_left' class = 'method' > < code > fn < a href = '#method.trim_left' class = 'fnname' > trim_left< / a > (& self) -> & < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns a string slice with leading whitespace removed.< / p >
< p > ' Whitespace' is defined according to the terms of the Unicode Derived
Core Property < code > White_Space< / code > .< / p >
< h1 id = 'text-directionality' class = 'section-header' > < a href = '#text-directionality' > Text directionality< / a > < / h1 >
< p > A string is a sequence of bytes. ' Left' in this context means the first
position of that byte string; for a language like Arabic or Hebrew
which are ' right to left' rather than ' left to right' , this will be
the < em > right< / em > side, not the left.< / p >
< h1 id = 'examples-29' class = 'section-header' > < a href = '#examples-29' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " Hello\tworld\t" < / span > ;
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " Hello\tworld\t" < / span > , < span class = 'ident' > s< / span > .< span class = 'ident' > trim_left< / span > ());< / pre >
< p > Directionality:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " English" < / span > ;
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > ' E' < / span > ) < span class = 'op' > ==< / span > < span class = 'ident' > s< / span > .< span class = 'ident' > trim_left< / span > ().< span class = 'ident' > chars< / span > ().< span class = 'ident' > next< / span > ());
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " עברית" < / span > ;
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > ' ע' < / span > ) < span class = 'op' > ==< / span > < span class = 'ident' > s< / span > .< span class = 'ident' > trim_left< / span > ().< span class = 'ident' > chars< / span > ().< span class = 'ident' > next< / span > ());< / pre >
< / div > < h4 id = 'method.trim_right' class = 'method' > < code > fn < a href = '#method.trim_right' class = 'fnname' > trim_right< / a > (& self) -> & < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns a string slice with trailing whitespace removed.< / p >
< p > ' Whitespace' is defined according to the terms of the Unicode Derived
Core Property < code > White_Space< / code > .< / p >
< h1 id = 'text-directionality-1' class = 'section-header' > < a href = '#text-directionality-1' > Text directionality< / a > < / h1 >
< p > A string is a sequence of bytes. ' Right' in this context means the last
position of that byte string; for a language like Arabic or Hebrew
which are ' right to left' rather than ' left to right' , this will be
the < em > left< / em > side, not the right.< / p >
< h1 id = 'examples-30' class = 'section-header' > < a href = '#examples-30' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " Hello\tworld\t" < / span > ;
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " Hello\tworld" < / span > , < span class = 'ident' > s< / span > .< span class = 'ident' > trim_right< / span > ());< / pre >
< p > Directionality:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " English " < / span > ;
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > ' h' < / span > ) < span class = 'op' > ==< / span > < span class = 'ident' > s< / span > .< span class = 'ident' > trim_right< / span > ().< span class = 'ident' > chars< / span > ().< span class = 'ident' > rev< / span > ().< span class = 'ident' > next< / span > ());
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " עברית " < / span > ;
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Some< / span > (< span class = 'string' > ' ת' < / span > ) < span class = 'op' > ==< / span > < span class = 'ident' > s< / span > .< span class = 'ident' > trim_right< / span > ().< span class = 'ident' > chars< / span > ().< span class = 'ident' > rev< / span > ().< span class = 'ident' > next< / span > ());< / pre >
< / div > < h4 id = 'method.trim_matches' class = 'method' > < code > fn < a href = '#method.trim_matches' class = 'fnname' > trim_matches< / a > < 'a, P> (& 'a self, pat: P) -> & 'a < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> , P::< a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Searcher< / a > : < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.DoubleEndedSearcher.html' title = 'core::str::pattern::DoubleEndedSearcher' > DoubleEndedSearcher< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns a string slice with all prefixes and suffixes that match a
pattern repeatedly removed.< / p >
< p > The pattern can be a < a href = "primitive.char.html" > < code > char< / code > < / a > or a closure that determines if a
character matches.< / p >
< h1 id = 'examples-31' class = 'section-header' > < a href = '#examples-31' > Examples< / a > < / h1 >
< p > Simple patterns:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " 11foo1bar11" < / span > .< span class = 'ident' > trim_matches< / span > (< span class = 'string' > ' 1' < / span > ), < span class = 'string' > " foo1bar" < / span > );
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " 123foo1bar123" < / span > .< span class = 'ident' > trim_matches< / span > (< span class = 'ident' > char< / span > ::< span class = 'ident' > is_numeric< / span > ), < span class = 'string' > " foo1bar" < / span > );
< span class = 'kw' > let< / span > < span class = 'ident' > x< / span > : < span class = 'kw-2' > & < / span > [_] < span class = 'op' > =< / span > < span class = 'kw-2' > & < / span > [< span class = 'string' > ' 1' < / span > , < span class = 'string' > ' 2' < / span > ];
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " 12foo1bar12" < / span > .< span class = 'ident' > trim_matches< / span > (< span class = 'ident' > x< / span > ), < span class = 'string' > " foo1bar" < / span > );< / pre >
< p > A more complex pattern, using a closure:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " 1foo1barXX" < / span > .< span class = 'ident' > trim_matches< / span > (< span class = 'op' > |< / span > < span class = 'ident' > c< / span > < span class = 'op' > |< / span > < span class = 'ident' > c< / span > < span class = 'op' > ==< / span > < span class = 'string' > ' 1' < / span > < span class = 'op' > ||< / span > < span class = 'ident' > c< / span > < span class = 'op' > ==< / span > < span class = 'string' > ' X' < / span > ), < span class = 'string' > " foo1bar" < / span > );< / pre >
< / div > < h4 id = 'method.trim_left_matches' class = 'method' > < code > fn < a href = '#method.trim_left_matches' class = 'fnname' > trim_left_matches< / a > < 'a, P> (& 'a self, pat: P) -> & 'a < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns a string slice with all prefixes that match a pattern
repeatedly removed.< / p >
< p > The pattern can be a < code > & str< / code > , < a href = "primitive.char.html" > < code > char< / code > < / a > , or a closure that determines if
a character matches.< / p >
< h1 id = 'text-directionality-2' class = 'section-header' > < a href = '#text-directionality-2' > Text directionality< / a > < / h1 >
< p > A string is a sequence of bytes. ' Left' in this context means the first
position of that byte string; for a language like Arabic or Hebrew
which are ' right to left' rather than ' left to right' , this will be
the < em > right< / em > side, not the left.< / p >
< h1 id = 'examples-32' class = 'section-header' > < a href = '#examples-32' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " 11foo1bar11" < / span > .< span class = 'ident' > trim_left_matches< / span > (< span class = 'string' > ' 1' < / span > ), < span class = 'string' > " foo1bar11" < / span > );
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " 123foo1bar123" < / span > .< span class = 'ident' > trim_left_matches< / span > (< span class = 'ident' > char< / span > ::< span class = 'ident' > is_numeric< / span > ), < span class = 'string' > " foo1bar123" < / span > );
< span class = 'kw' > let< / span > < span class = 'ident' > x< / span > : < span class = 'kw-2' > & < / span > [_] < span class = 'op' > =< / span > < span class = 'kw-2' > & < / span > [< span class = 'string' > ' 1' < / span > , < span class = 'string' > ' 2' < / span > ];
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " 12foo1bar12" < / span > .< span class = 'ident' > trim_left_matches< / span > (< span class = 'ident' > x< / span > ), < span class = 'string' > " foo1bar12" < / span > );< / pre >
< / div > < h4 id = 'method.trim_right_matches' class = 'method' > < code > fn < a href = '#method.trim_right_matches' class = 'fnname' > trim_right_matches< / a > < 'a, P> (& 'a self, pat: P) -> & 'a < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> , P::< a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Searcher< / a > : < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.ReverseSearcher.html' title = 'core::str::pattern::ReverseSearcher' > ReverseSearcher< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns a string slice with all suffixes that match a pattern
repeatedly removed.< / p >
< p > The pattern can be a < code > & str< / code > , < a href = "primitive.char.html" > < code > char< / code > < / a > , or a closure that
determines if a character matches.< / p >
< h1 id = 'text-directionality-3' class = 'section-header' > < a href = '#text-directionality-3' > Text directionality< / a > < / h1 >
< p > A string is a sequence of bytes. ' Right' in this context means the last
position of that byte string; for a language like Arabic or Hebrew
which are ' right to left' rather than ' left to right' , this will be
the < em > left< / em > side, not the right.< / p >
< h1 id = 'examples-33' class = 'section-header' > < a href = '#examples-33' > Examples< / a > < / h1 >
< p > Simple patterns:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " 11foo1bar11" < / span > .< span class = 'ident' > trim_right_matches< / span > (< span class = 'string' > ' 1' < / span > ), < span class = 'string' > " 11foo1bar" < / span > );
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " 123foo1bar123" < / span > .< span class = 'ident' > trim_right_matches< / span > (< span class = 'ident' > char< / span > ::< span class = 'ident' > is_numeric< / span > ), < span class = 'string' > " 123foo1bar" < / span > );
< span class = 'kw' > let< / span > < span class = 'ident' > x< / span > : < span class = 'kw-2' > & < / span > [_] < span class = 'op' > =< / span > < span class = 'kw-2' > & < / span > [< span class = 'string' > ' 1' < / span > , < span class = 'string' > ' 2' < / span > ];
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " 12foo1bar12" < / span > .< span class = 'ident' > trim_right_matches< / span > (< span class = 'ident' > x< / span > ), < span class = 'string' > " 12foo1bar" < / span > );< / pre >
< p > A more complex pattern, using a closure:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " 1fooX" < / span > .< span class = 'ident' > trim_left_matches< / span > (< span class = 'op' > |< / span > < span class = 'ident' > c< / span > < span class = 'op' > |< / span > < span class = 'ident' > c< / span > < span class = 'op' > ==< / span > < span class = 'string' > ' 1' < / span > < span class = 'op' > ||< / span > < span class = 'ident' > c< / span > < span class = 'op' > ==< / span > < span class = 'string' > ' X' < / span > ), < span class = 'string' > " fooX" < / span > );< / pre >
< / div > < h4 id = 'method.parse' class = 'method' > < code > fn < a href = '#method.parse' class = 'fnname' > parse< / a > < F> (& self) -> < a class = 'enum' href = 'https://doc.rust-lang.org/nightly/core/result/enum.Result.html' title = 'core::result::Result' > Result< / a > < F, F::< a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/trait.FromStr.html' title = 'core::str::FromStr' > Err< / a > > < span class = 'where' > where F: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/trait.FromStr.html' title = 'core::str::FromStr' > FromStr< / a > < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Parses this string slice into another type.< / p >
< p > Because < code > parse()< / code > is so general, it can cause problems with type
inference. As such, < code > parse()< / code > is one of the few times you' ll see
the syntax affectionately known as the ' turbofish' : < code > ::< > < / code > . This
helps the inference algorithm understand specifically which type
you' re trying to parse into.< / p >
< p > < code > parse()< / code > can parse any type that implements the < a href = "str/trait.FromStr.html" > < code > FromStr< / code > < / a > trait.< / p >
< h1 id = 'errors' class = 'section-header' > < a href = '#errors' > Errors< / a > < / h1 >
< p > Will return < a href = "str/trait.FromStr.html#associatedtype.Err" > < code > Err< / code > < / a > if it' s not possible to parse this string slice into
the desired type.< / p >
< h1 id = 'example' class = 'section-header' > < a href = '#example' > Example< / a > < / h1 >
< p > Basic usage< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > four< / span > : < span class = 'ident' > u32< / span > < span class = 'op' > =< / span > < span class = 'string' > " 4" < / span > .< span class = 'ident' > parse< / span > ().< span class = 'ident' > unwrap< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'number' > 4< / span > , < span class = 'ident' > four< / span > );< / pre >
< p > Using the ' turbofish' instead of annotating < code > four< / code > :< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > four< / span > < span class = 'op' > =< / span > < span class = 'string' > " 4" < / span > .< span class = 'ident' > parse< / span > ::< span class = 'op' > < < / span > < span class = 'ident' > u32< / span > < span class = 'op' > > < / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'prelude-val' > Ok< / span > (< span class = 'number' > 4< / span > ), < span class = 'ident' > four< / span > );< / pre >
< p > Failing to parse:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > nope< / span > < span class = 'op' > =< / span > < span class = 'string' > " j" < / span > .< span class = 'ident' > parse< / span > ::< span class = 'op' > < < / span > < span class = 'ident' > u32< / span > < span class = 'op' > > < / span > ();
< span class = 'macro' > assert< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > nope< / span > .< span class = 'ident' > is_err< / span > ());< / pre >
< / div > < h4 id = 'method.replace' class = 'method' > < code > fn < a href = '#method.replace' class = 'fnname' > replace< / a > < 'a, P> (& 'a self, from: P, to: & < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > ) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/collections/string/struct.String.html' title = 'collections::string::String' > String< / a > < span class = 'where' > where P: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title = 'core::str::pattern::Pattern' > Pattern< / a > < 'a> < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Replaces all matches of a pattern with another string.< / p >
< p > < code > replace< / code > creates a new < a href = "string/struct.String.html" > < code > String< / code > < / a > , and copies the data from this string slice into it.
While doing so, it attempts to find matches of a pattern. If it finds any, it
replaces them with the replacement string slice.< / p >
< h1 id = 'examples-34' class = 'section-header' > < a href = '#examples-34' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " this is old" < / span > ;
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " this is new" < / span > , < span class = 'ident' > s< / span > .< span class = 'ident' > replace< / span > (< span class = 'string' > " old" < / span > , < span class = 'string' > " new" < / span > ));< / pre >
< p > When the pattern doesn' t match:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " this is old" < / span > ;
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > s< / span > , < span class = 'ident' > s< / span > .< span class = 'ident' > replace< / span > (< span class = 'string' > " cookie monster" < / span > , < span class = 'string' > " little lamb" < / span > ));< / pre >
< / div > < h4 id = 'method.to_lowercase' class = 'method' > < code > fn < a href = '#method.to_lowercase' class = 'fnname' > to_lowercase< / a > (& self) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/collections/string/struct.String.html' title = 'collections::string::String' > String< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.2.0' > 1.2.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns the lowercase equivalent of this string slice, as a new < a href = "string/struct.String.html" > < code > String< / code > < / a > .< / p >
< p > ' Lowercase' is defined according to the terms of the Unicode Derived Core Property
< code > Lowercase< / code > .< / p >
< h1 id = 'examples-35' class = 'section-header' > < a href = '#examples-35' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " HELLO" < / span > ;
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " hello" < / span > , < span class = 'ident' > s< / span > .< span class = 'ident' > to_lowercase< / span > ());< / pre >
< p > A tricky example, with sigma:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > sigma< / span > < span class = 'op' > =< / span > < span class = 'string' > " Σ" < / span > ;
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " σ " < / span > , < span class = 'ident' > sigma< / span > .< span class = 'ident' > to_lowercase< / span > ());
< span class = 'comment' > // but at the end of a word, it' s ς, not σ :< / span >
< span class = 'kw' > let< / span > < span class = 'ident' > odysseus< / span > < span class = 'op' > =< / span > < span class = 'string' > " ὈΔΥΣΣΕΎΣ" < / span > ;
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " ὀδυσσεύς" < / span > , < span class = 'ident' > odysseus< / span > .< span class = 'ident' > to_lowercase< / span > ());< / pre >
< p > Languages without case are not changed:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > new_year< / span > < span class = 'op' > =< / span > < span class = 'string' > " 农历新年" < / span > ;
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > new_year< / span > , < span class = 'ident' > new_year< / span > .< span class = 'ident' > to_lowercase< / span > ());< / pre >
< / div > < h4 id = 'method.to_uppercase' class = 'method' > < code > fn < a href = '#method.to_uppercase' class = 'fnname' > to_uppercase< / a > (& self) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/collections/string/struct.String.html' title = 'collections::string::String' > String< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.2.0' > 1.2.0< / div > < / h4 >
< div class = 'docblock' > < p > Returns the uppercase equivalent of this string slice, as a new < a href = "string/struct.String.html" > < code > String< / code > < / a > .< / p >
< p > ' Uppercase' is defined according to the terms of the Unicode Derived Core Property
< code > Uppercase< / code > .< / p >
< h1 id = 'examples-36' class = 'section-header' > < a href = '#examples-36' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > s< / span > < span class = 'op' > =< / span > < span class = 'string' > " hello" < / span > ;
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'string' > " HELLO" < / span > , < span class = 'ident' > s< / span > .< span class = 'ident' > to_uppercase< / span > ());< / pre >
< p > Scripts without case are not changed:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > new_year< / span > < span class = 'op' > =< / span > < span class = 'string' > " 农历新年" < / span > ;
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > new_year< / span > , < span class = 'ident' > new_year< / span > .< span class = 'ident' > to_uppercase< / span > ());< / pre >
2016-10-09 07:40:00 -05:00
< / div > < h4 id = 'method.escape_debug' class = 'method' > < code > fn < a href = '#method.escape_debug' class = 'fnname' > escape_debug< / a > (& self) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/collections/string/struct.String.html' title = 'collections::string::String' > String< / a > < / code > < / h4 >
< div class = 'stability' > < em class = 'stab unstable' > Unstable (< code > str_escape< / code > )< p > : return type may change to be an iterator< / p >
< / em > < / div > < div class = 'docblock' > < p > Escapes each char in < code > s< / code > with < code > char::escape_debug< / code > .< / p >
2016-09-11 13:41:24 -05:00
< / div > < h4 id = 'method.escape_default' class = 'method' > < code > fn < a href = '#method.escape_default' class = 'fnname' > escape_default< / a > (& self) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/collections/string/struct.String.html' title = 'collections::string::String' > String< / a > < / code > < / h4 >
< div class = 'stability' > < em class = 'stab unstable' > Unstable (< code > str_escape< / code > )< p > : return type may change to be an iterator< / p >
< / em > < / div > < div class = 'docblock' > < p > Escapes each char in < code > s< / code > with < code > char::escape_default< / code > .< / p >
< / div > < h4 id = 'method.escape_unicode' class = 'method' > < code > fn < a href = '#method.escape_unicode' class = 'fnname' > escape_unicode< / a > (& self) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/collections/string/struct.String.html' title = 'collections::string::String' > String< / a > < / code > < / h4 >
< div class = 'stability' > < em class = 'stab unstable' > Unstable (< code > str_escape< / code > )< p > : return type may change to be an iterator< / p >
< / em > < / div > < div class = 'docblock' > < p > Escapes each char in < code > s< / code > with < code > char::escape_unicode< / code > .< / p >
< / div > < h4 id = 'method.into_string' class = 'method' > < code > fn < a href = '#method.into_string' class = 'fnname' > into_string< / a > (self: < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html' title = 'alloc::boxed::Box' > Box< / a > < < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > > ) -> < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/collections/string/struct.String.html' title = 'collections::string::String' > String< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.4.0' > 1.4.0< / div > < / h4 >
< div class = 'docblock' > < p > Converts a < code > Box< str> < / code > into a < a href = "string/struct.String.html" > < code > String< / code > < / a > without copying or allocating.< / p >
< h1 id = 'examples-37' class = 'section-header' > < a href = '#examples-37' > Examples< / a > < / h1 >
< p > Basic usage:< / p >
< pre class = 'rust rust-example-rendered' >
< span class = 'kw' > let< / span > < span class = 'ident' > string< / span > < span class = 'op' > =< / span > < span class = 'ident' > String< / span > ::< span class = 'ident' > from< / span > (< span class = 'string' > " birthday gift" < / span > );
< span class = 'kw' > let< / span > < span class = 'ident' > boxed_str< / span > < span class = 'op' > =< / span > < span class = 'ident' > string< / span > .< span class = 'ident' > clone< / span > ().< span class = 'ident' > into_boxed_str< / span > ();
< span class = 'macro' > assert_eq< / span > < span class = 'macro' > !< / span > (< span class = 'ident' > boxed_str< / span > .< span class = 'ident' > into_string< / span > (), < span class = 'ident' > string< / span > );< / pre >
< / div > < / div > < h2 id = 'implementations' > Trait Implementations< / h2 > < h3 class = 'impl' > < span class = 'in-band' > < code > impl < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html' title = 'core::cmp::Eq' > Eq< / a > for < a class = 'enum' href = '../mime/enum.TopLevel.html' title = 'mime::TopLevel' > TopLevel< / a > < / code > < / span > < span class = 'out-of-band' > < div class = 'ghost' > < / div > < a id = 'src-53' class = 'srclink' href = '../src/mime/lib.rs.html#138' title = 'goto source code' > [src]< / a > < / span > < / h3 >
< div class = 'impl-items' > < / div > < h3 class = 'impl' > < span class = 'in-band' > < code > impl < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html' title = 'core::hash::Hash' > Hash< / a > for < a class = 'enum' href = '../mime/enum.TopLevel.html' title = 'mime::TopLevel' > TopLevel< / a > < / code > < / span > < span class = 'out-of-band' > < div class = 'ghost' > < / div > < a id = 'src-57' class = 'srclink' href = '../src/mime/lib.rs.html#138' title = 'goto source code' > [src]< / a > < / span > < / h3 >
< div class = 'impl-items' > < h4 id = 'method.hash' class = 'method' > < code > fn < a href = 'https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html#tymethod.hash' class = 'fnname' > hash< / a > < __H: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/hash/trait.Hasher.html' title = 'core::hash::Hasher' > Hasher< / a > > (& self, __arg_0: & mut __H)< / code > < / h4 >
< div class = 'docblock' > < p > Feeds this value into the state given, updating the hasher as necessary.< / p >
< / div > < h4 id = 'method.hash_slice' class = 'method' > < code > fn < a href = 'https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html#method.hash_slice' class = 'fnname' > hash_slice< / a > < H> (data: < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.slice.html' > & [Self]< / a > , state: & mut H) < span class = 'where' > where H: < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/hash/trait.Hasher.html' title = 'core::hash::Hasher' > Hasher< / a > < / span > < / code > < div class = 'since' title = 'Stable since Rust version 1.3.0' > 1.3.0< / div > < / h4 >
< div class = 'docblock' > < p > Feeds a slice of this type into the state provided.< / p >
< / div > < / div > < h3 class = 'impl' > < span class = 'in-band' > < code > impl < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html' title = 'core::fmt::Debug' > Debug< / a > for < a class = 'enum' href = '../mime/enum.TopLevel.html' title = 'mime::TopLevel' > TopLevel< / a > < / code > < / span > < span class = 'out-of-band' > < div class = 'ghost' > < / div > < a id = 'src-63' class = 'srclink' href = '../src/mime/lib.rs.html#138' title = 'goto source code' > [src]< / a > < / span > < / h3 >
< div class = 'impl-items' > < h4 id = 'method.fmt' class = 'method' > < code > fn < a href = 'https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt' class = 'fnname' > fmt< / a > (& self, __arg_0: & mut < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html' title = 'core::fmt::Formatter' > Formatter< / a > ) -> < a class = 'type' href = 'https://doc.rust-lang.org/nightly/core/fmt/type.Result.html' title = 'core::fmt::Result' > Result< / a > < / code > < / h4 >
< div class = 'docblock' > < p > Formats the value using the given formatter.< / p >
< / div > < / div > < h3 class = 'impl' > < span class = 'in-band' > < code > impl < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title = 'core::clone::Clone' > Clone< / a > for < a class = 'enum' href = '../mime/enum.TopLevel.html' title = 'mime::TopLevel' > TopLevel< / a > < / code > < / span > < span class = 'out-of-band' > < div class = 'ghost' > < / div > < a id = 'src-78' class = 'srclink' href = '../src/mime/lib.rs.html#138' title = 'goto source code' > [src]< / a > < / span > < / h3 >
< div class = 'impl-items' > < h4 id = 'method.clone' class = 'method' > < code > fn < a href = 'https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone' class = 'fnname' > clone< / a > (& self) -> < a class = 'enum' href = '../mime/enum.TopLevel.html' title = 'mime::TopLevel' > TopLevel< / a > < / code > < / h4 >
< div class = 'docblock' > < p > Returns a copy of the value. < a href = "https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone" > Read more< / a > < / p >
< / div > < h4 id = 'method.clone_from' class = 'method' > < code > fn < a href = 'https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from' class = 'fnname' > clone_from< / a > (& mut self, source: & Self)< / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > Performs copy-assignment from < code > source< / code > . < a href = "https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from" > Read more< / a > < / p >
< / div > < / div > < h3 class = 'impl' > < span class = 'in-band' > < code > impl < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/ops/trait.Deref.html' title = 'core::ops::Deref' > Deref< / a > for < a class = 'enum' href = '../mime/enum.TopLevel.html' title = 'mime::TopLevel' > TopLevel< / a > < / code > < / span > < span class = 'out-of-band' > < div class = 'ghost' > < / div > < a id = 'src-98' class = 'srclink' href = '../src/mime/lib.rs.html#153-158' title = 'goto source code' > [src]< / a > < / span > < / h3 >
< div class = 'impl-items' > < h4 id = 'associatedtype.Target' class = 'type' > < code > type < a href = 'https://doc.rust-lang.org/nightly/core/ops/trait.Deref.html#associatedtype.Target' class = 'type' > Target< / a > = < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > < / code > < / h4 >
< div class = 'docblock' > < p > The resulting type after dereferencing< / p >
< / div > < h4 id = 'method.deref' class = 'method' > < code > fn < a href = 'https://doc.rust-lang.org/nightly/core/ops/trait.Deref.html#tymethod.deref' class = 'fnname' > deref< / a > (& self) -> & < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > < / code > < / h4 >
< div class = 'docblock' > < p > The method called to dereference a value< / p >
< / div > < / div > < h3 class = 'impl' > < span class = 'in-band' > < code > impl < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html' title = 'core::cmp::PartialEq' > PartialEq< / a > for < a class = 'enum' href = '../mime/enum.TopLevel.html' title = 'mime::TopLevel' > TopLevel< / a > < / code > < / span > < span class = 'out-of-band' > < div class = 'ghost' > < / div > < a id = 'src-102' class = 'srclink' href = '../src/mime/lib.rs.html#160-168' title = 'goto source code' > [src]< / a > < / span > < / h3 >
< div class = 'impl-items' > < h4 id = 'method.eq' class = 'method' > < code > fn < a href = 'https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq' class = 'fnname' > eq< / a > (& self, other: & < a class = 'enum' href = '../mime/enum.TopLevel.html' title = 'mime::TopLevel' > TopLevel< / a > ) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.bool.html' > bool< / a > < / code > < / h4 >
< div class = 'docblock' > < p > This method tests for < code > self< / code > and < code > other< / code > values to be equal, and is used by < code > ==< / code > . < a href = "https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq" > Read more< / a > < / p >
< / div > < h4 id = 'method.ne' class = 'method' > < code > fn < a href = 'https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#method.ne' class = 'fnname' > ne< / a > (& self, other: & Rhs) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.bool.html' > bool< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > This method tests for < code > !=< / code > .< / p >
< / div > < / div > < h3 class = 'impl' > < span class = 'in-band' > < code > impl < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html' title = 'core::cmp::PartialEq' > PartialEq< / a > < < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/collections/string/struct.String.html' title = 'collections::string::String' > String< / a > > for < a class = 'enum' href = '../mime/enum.TopLevel.html' title = 'mime::TopLevel' > TopLevel< / a > < / code > < / span > < span class = 'out-of-band' > < div class = 'ghost' > < / div > < a id = 'src-108' class = 'srclink' href = '../src/mime/lib.rs.html#170-174' title = 'goto source code' > [src]< / a > < / span > < / h3 >
< div class = 'impl-items' > < h4 id = 'method.eq-1' class = 'method' > < code > fn < a href = 'https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq' class = 'fnname' > eq< / a > (& self, other: & < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/collections/string/struct.String.html' title = 'collections::string::String' > String< / a > ) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.bool.html' > bool< / a > < / code > < / h4 >
< div class = 'docblock' > < p > This method tests for < code > self< / code > and < code > other< / code > values to be equal, and is used by < code > ==< / code > . < a href = "https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq" > Read more< / a > < / p >
< / div > < h4 id = 'method.ne-1' class = 'method' > < code > fn < a href = 'https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#method.ne' class = 'fnname' > ne< / a > (& self, other: & Rhs) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.bool.html' > bool< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > This method tests for < code > !=< / code > .< / p >
< / div > < / div > < h3 class = 'impl' > < span class = 'in-band' > < code > impl < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html' title = 'core::cmp::PartialEq' > PartialEq< / a > < < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > > for < a class = 'enum' href = '../mime/enum.TopLevel.html' title = 'mime::TopLevel' > TopLevel< / a > < / code > < / span > < span class = 'out-of-band' > < div class = 'ghost' > < / div > < a id = 'src-112' class = 'srclink' href = '../src/mime/lib.rs.html#176-180' title = 'goto source code' > [src]< / a > < / span > < / h3 >
< div class = 'impl-items' > < h4 id = 'method.eq-2' class = 'method' > < code > fn < a href = 'https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq' class = 'fnname' > eq< / a > (& self, other: & < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > ) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.bool.html' > bool< / a > < / code > < / h4 >
< div class = 'docblock' > < p > This method tests for < code > self< / code > and < code > other< / code > values to be equal, and is used by < code > ==< / code > . < a href = "https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq" > Read more< / a > < / p >
< / div > < h4 id = 'method.ne-2' class = 'method' > < code > fn < a href = 'https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#method.ne' class = 'fnname' > ne< / a > (& self, other: & Rhs) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.bool.html' > bool< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > This method tests for < code > !=< / code > .< / p >
< / div > < / div > < h3 class = 'impl' > < span class = 'in-band' > < code > impl< 'a> < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html' title = 'core::cmp::PartialEq' > PartialEq< / a > < & 'a < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > > for < a class = 'enum' href = '../mime/enum.TopLevel.html' title = 'mime::TopLevel' > TopLevel< / a > < / code > < / span > < span class = 'out-of-band' > < div class = 'ghost' > < / div > < a id = 'src-116' class = 'srclink' href = '../src/mime/lib.rs.html#182-186' title = 'goto source code' > [src]< / a > < / span > < / h3 >
< div class = 'impl-items' > < h4 id = 'method.eq-3' class = 'method' > < code > fn < a href = 'https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq' class = 'fnname' > eq< / a > (& self, other: & & 'a < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > ) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.bool.html' > bool< / a > < / code > < / h4 >
< div class = 'docblock' > < p > This method tests for < code > self< / code > and < code > other< / code > values to be equal, and is used by < code > ==< / code > . < a href = "https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq" > Read more< / a > < / p >
< / div > < h4 id = 'method.ne-3' class = 'method' > < code > fn < a href = 'https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#method.ne' class = 'fnname' > ne< / a > (& self, other: & Rhs) -> < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.bool.html' > bool< / a > < / code > < div class = 'since' title = 'Stable since Rust version 1.0.0' > 1.0.0< / div > < / h4 >
< div class = 'docblock' > < p > This method tests for < code > !=< / code > .< / p >
< / div > < / div > < h3 class = 'impl' > < span class = 'in-band' > < code > impl < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html' title = 'core::fmt::Display' > Display< / a > for < a class = 'enum' href = '../mime/enum.TopLevel.html' title = 'mime::TopLevel' > TopLevel< / a > < / code > < / span > < span class = 'out-of-band' > < div class = 'ghost' > < / div > < a id = 'src-134' class = 'srclink' href = '../src/mime/lib.rs.html#206-213' title = 'goto source code' > [src]< / a > < / span > < / h3 >
< div class = 'impl-items' > < h4 id = 'method.fmt-1' class = 'method' > < code > fn < a href = 'https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html#tymethod.fmt' class = 'fnname' > fmt< / a > (& self, fmt: & mut < a class = 'struct' href = 'https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html' title = 'core::fmt::Formatter' > Formatter< / a > ) -> < a class = 'type' href = 'https://doc.rust-lang.org/nightly/core/fmt/type.Result.html' title = 'core::fmt::Result' > Result< / a > < / code > < / h4 >
< div class = 'docblock' > < p > Formats the value using the given formatter.< / p >
< / div > < / div > < h3 class = 'impl' > < span class = 'in-band' > < code > impl < a class = 'trait' href = 'https://doc.rust-lang.org/nightly/core/str/trait.FromStr.html' title = 'core::str::FromStr' > FromStr< / a > for < a class = 'enum' href = '../mime/enum.TopLevel.html' title = 'mime::TopLevel' > TopLevel< / a > < / code > < / span > < span class = 'out-of-band' > < div class = 'ghost' > < / div > < a id = 'src-139' class = 'srclink' href = '../src/mime/lib.rs.html#215-223' title = 'goto source code' > [src]< / a > < / span > < / h3 >
< div class = 'impl-items' > < h4 id = 'associatedtype.Err' class = 'type' > < code > type < a href = 'https://doc.rust-lang.org/nightly/core/str/trait.FromStr.html#associatedtype.Err' class = 'type' > Err< / a > = < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.tuple.html' > ()< / a > < / code > < / h4 >
< div class = 'docblock' > < p > The associated error which can be returned from parsing.< / p >
< / div > < h4 id = 'method.from_str' class = 'method' > < code > fn < a href = 'https://doc.rust-lang.org/nightly/core/str/trait.FromStr.html#tymethod.from_str' class = 'fnname' > from_str< / a > (s: & < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.str.html' > str< / a > ) -> < a class = 'enum' href = 'https://doc.rust-lang.org/nightly/core/result/enum.Result.html' title = 'core::result::Result' > Result< / a > < < a class = 'enum' href = '../mime/enum.TopLevel.html' title = 'mime::TopLevel' > TopLevel< / a > , < a class = 'primitive' href = 'https://doc.rust-lang.org/nightly/std/primitive.tuple.html' > ()< / a > > < / code > < / h4 >
< div class = 'docblock' > < p > Parses a string < code > s< / code > to return a value of this type. < a href = "https://doc.rust-lang.org/nightly/core/str/trait.FromStr.html#tymethod.from_str" > Read more< / a > < / p >
< / div > < / div > < / section >
< section id = 'search' class = "content hidden" > < / section >
< section class = "footer" > < / section >
< aside id = "help" class = "hidden" >
< div >
< h1 class = "hidden" > Help< / h1 >
< div class = "shortcuts" >
< h2 > Keyboard Shortcuts< / h2 >
< dl >
< dt > ?< / dt >
< dd > Show this help dialog< / dd >
< dt > S< / dt >
< dd > Focus the search field< / dd >
< dt > ⇤ < / dt >
< dd > Move up in search results< / dd >
< dt > ⇥ < / dt >
< dd > Move down in search results< / dd >
< dt > ⏎ < / dt >
< dd > Go to active search result< / dd >
< dt > +< / dt >
< dd > Collapse/expand all sections< / dd >
< / dl >
< / div >
< div class = "infos" >
< h2 > Search Tricks< / h2 >
< p >
Prefix searches with a type followed by a colon (e.g.
< code > fn:< / code > ) to restrict the search to a given type.
< / p >
< p >
Accepted types are: < code > fn< / code > , < code > mod< / code > ,
< code > struct< / code > , < code > enum< / code > ,
< code > trait< / code > , < code > type< / code > , < code > macro< / code > ,
and < code > const< / code > .
< / p >
< p >
Search functions by type signature (e.g.
< code > vec -> usize< / code > or < code > * -> vec< / code > )
< / p >
< / div >
< / div >
< / aside >
< script >
window.rootPath = "../";
window.currentCrate = "mime";
window.playgroundUrl = "";
< / script >
< script src = "../jquery.js" > < / script >
< script src = "../main.js" > < / script >
< script defer src = "../search-index.js" > < / script >
< / body >
< / html >