Trait traitsequence::interface::Sequence
source · pub trait Sequence<Item, Subsequence: Sequence<Item, Subsequence> + ?Sized>: Index<usize, Output = Item> + Index<Range<usize>, Output = Subsequence> {
type Iterator<'a>: DoubleEndedIterator<Item = &'a Item>
where Self: 'a,
Item: 'a;
// Required methods
fn iter(&self) -> Self::Iterator<'_>;
fn len(&self) -> usize;
// Provided methods
fn prefix(&self, len: usize) -> &Subsequence { ... }
fn suffix(&self, len: usize) -> &Subsequence { ... }
fn is_empty(&self) -> bool { ... }
fn first(&self) -> Option<&Item> { ... }
fn last(&self) -> Option<&Item> { ... }
fn is_proper_subsequence_of(&self, other: &Self) -> bool
where Item: Eq { ... }
fn contains(&self, item: &Item) -> bool
where Item: Eq { ... }
fn forward_merge_iter_assume_mergeable<'a>(
&'a self,
suffix: &'a Self
) -> Chain<Self::Iterator<'a>, Skip<Self::Iterator<'a>>>
where Item: Eq { ... }
fn backward_merge_iter_assume_mergeable<'a>(
&'a self,
suffix: &'a Self
) -> Chain<Self::Iterator<'a>, Skip<Self::Iterator<'a>>>
where Item: Eq { ... }
fn to_debug_string(&self) -> String
where Item: Debug { ... }
}
Expand description
A type behaving like a sequence over the type Item
.
Required Associated Types§
sourcetype Iterator<'a>: DoubleEndedIterator<Item = &'a Item>
where
Self: 'a,
Item: 'a
type Iterator<'a>: DoubleEndedIterator<Item = &'a Item> where Self: 'a, Item: 'a
The iterator type of the sequence.
Required Methods§
Provided Methods§
sourcefn prefix(&self, len: usize) -> &Subsequence
fn prefix(&self, len: usize) -> &Subsequence
Returns a prefix with length len
of this sequence.
Panics if len >= self.len()
.
sourcefn suffix(&self, len: usize) -> &Subsequence
fn suffix(&self, len: usize) -> &Subsequence
Returns a suffix with length len
of this sequence.
Panics if len >= self.len()
.
sourcefn is_proper_subsequence_of(&self, other: &Self) -> boolwhere
Item: Eq,
fn is_proper_subsequence_of(&self, other: &Self) -> boolwhere Item: Eq,
Returns true if this is a proper subsequence of the given sequence. Proper means that the sequences are not equal.
sourcefn contains(&self, item: &Item) -> boolwhere
Item: Eq,
fn contains(&self, item: &Item) -> boolwhere Item: Eq,
Returns true if this sequence contains the given item.
sourcefn forward_merge_iter_assume_mergeable<'a>(
&'a self,
suffix: &'a Self
) -> Chain<Self::Iterator<'a>, Skip<Self::Iterator<'a>>>where
Item: Eq,
fn forward_merge_iter_assume_mergeable<'a>( &'a self, suffix: &'a Self ) -> Chain<Self::Iterator<'a>, Skip<Self::Iterator<'a>>>where Item: Eq,
Returns an iterator over this sequence merged before the given other sequence under the assumption that the sequences can be merged this way. A merge is possible if a non-empty suffix of this sequence equals a non-empty prefix of the other sequence.
The method panics if this sequence does not contain the first item of the other sequence or the other sequence is empty. The method does not fail if the sequences are not mergeable for other reasons.
sourcefn backward_merge_iter_assume_mergeable<'a>(
&'a self,
suffix: &'a Self
) -> Chain<Self::Iterator<'a>, Skip<Self::Iterator<'a>>>where
Item: Eq,
fn backward_merge_iter_assume_mergeable<'a>( &'a self, suffix: &'a Self ) -> Chain<Self::Iterator<'a>, Skip<Self::Iterator<'a>>>where Item: Eq,
Returns an iterator over this sequence merged after the given other sequence under the assumption that the sequences can be merged this way. A merge is possible if a non-empty prefix of this sequence equals a non-empty suffix of the other sequence.
The method panics if the other sequence does not contain the first item of this sequence or this sequence is empty. The method does not fail if the sequences are not mergeable for other reasons.
sourcefn to_debug_string(&self) -> Stringwhere
Item: Debug,
fn to_debug_string(&self) -> Stringwhere Item: Debug,
Converts the sequence to a string using the debug formatting of the items.
use traitsequence::interface::Sequence;
let sequence = [0, 2, 1];
debug_assert_eq!(sequence.to_debug_string(), "[0, 2, 1]".to_string());
let sequence = ["a", "c", "b"];
debug_assert_eq!(sequence.to_debug_string(), "[\"a\", \"c\", \"b\"]".to_string());