pub trait ImplStrChunks {
// Required methods
fn str_chunks(&self, chunk_size: usize) -> StrChunks<'_> ⓘ;
fn str_chunks_exact(&self, chunk_size: usize) -> StrChunksExact<'_> ⓘ;
fn str_rchunks(&self, chunk_size: usize) -> StrRChunks<'_> ⓘ;
fn str_rchunks_exact(&self, chunk_size: usize) -> StrRChunksExact<'_> ⓘ;
}Expand description
Trait implemented on &str to provide convenience methods.
Import this!
§Example
use str_chunks::ImplStrChunks;
let s = "lorem";
let mut iter = s.str_chunks(2);
assert_eq!(iter.next(), Some("lo"));
assert_eq!(iter.next(), Some("re"));
assert_eq!(iter.next(), Some("m"));
assert_eq!(iter.next(), None);
assert_eq!(iter.remaining(), "");Required Methods§
Sourcefn str_chunks(&self, chunk_size: usize) -> StrChunks<'_> ⓘ
fn str_chunks(&self, chunk_size: usize) -> StrChunks<'_> ⓘ
Returns an iterator over chunk_size chars at a time,
starting at the beginning of the str.
The chunks are &str slices and do not overlap.
If chunk_size does not divide the char-length of the str,
then the last chunk will not have char-length chunk_size.
See str_chunks_exact for a variant of this iterator that returns chunks of always
exactly chunk_size elements, and str_rchunks for the same iterator but starting at
the end of the str.
§Panics
Panics if chunk_size is 0.
§Example
use str_chunks::*;
let s = "lorem";
let mut iter = s.str_chunks(2);
assert_eq!(iter.next(), Some("lo"));
assert_eq!(iter.next(), Some("re"));
assert_eq!(iter.next(), Some("m"));
assert_eq!(iter.next(), None);
assert_eq!(iter.remaining(), "");Sourcefn str_chunks_exact(&self, chunk_size: usize) -> StrChunksExact<'_> ⓘ
fn str_chunks_exact(&self, chunk_size: usize) -> StrChunksExact<'_> ⓘ
Returns an iterator over chunk_size chars at a time,
starting at the beginning of the str.
The chunks are &str slices and do not overlap.
If chunk_size does not divide the char-length of the str,
then the last up to chunk_size-1 chars will be omitted and can be retrieved from the
remaining function of the iterator after the iterator has returned None.
See str_chunks for a variant of this iterator that also returns the remainder as a
smaller chunk.
§Panics
Panics if chunk_size is 0.
§Example
use str_chunks::*;
let s = "lorem";
let mut iter = s.str_chunks_exact(2);
assert_eq!(iter.next(), Some("lo"));
assert_eq!(iter.next(), Some("re"));
assert_eq!(iter.next(), None);
assert_eq!(iter.remaining(), "m");Sourcefn str_rchunks(&self, chunk_size: usize) -> StrRChunks<'_> ⓘ
fn str_rchunks(&self, chunk_size: usize) -> StrRChunks<'_> ⓘ
Returns an iterator over chunk_size chars at a time,
starting at the end of the str.
The chunks are &str slices and do not overlap.
If chunk_size does not divide the char-length of the str,
then the last chunk will not have char-length chunk_size.
See str_rchunks_exact for a variant of this iterator that returns chunks of always
exactly chunk_size elements, and str_chunks for the same iterator but starting at the
beginning of the str.
§Panics
Panics if chunk_size is 0.
§Example
use str_chunks::*;
let s = "lorem";
let mut iter = s.str_rchunks(2);
assert_eq!(iter.next(), Some("em"));
assert_eq!(iter.next(), Some("or"));
assert_eq!(iter.next(), Some("l"));
assert_eq!(iter.next(), None);
assert_eq!(iter.remaining(), "");Sourcefn str_rchunks_exact(&self, chunk_size: usize) -> StrRChunksExact<'_> ⓘ
fn str_rchunks_exact(&self, chunk_size: usize) -> StrRChunksExact<'_> ⓘ
Returns an iterator over chunk_size chars at a time,
starting at the end of the str.
The chunks are &str slices and do not overlap.
If chunk_size does not divide the char-length of the str,
then the last up to chunk_size-1 chars will be omitted and can be retrieved from the
remaining function of the iterator after the iterator has
returned None.
See str_rchunks for a variant of this iterator that also returns the remainder as a
smaller chunk, and str_chunks_exact for the same iterator but starting at the beginning
of the str.
§Panics
Panics if chunk_size is 0.
§Example
use str_chunks::*;
let s = "lorem";
let mut iter = s.str_rchunks_exact(2);
assert_eq!(iter.next(), Some("em"));
assert_eq!(iter.next(), Some("or"));
assert_eq!(iter.next(), None);
assert_eq!(iter.remaining(), "l");