pub trait ConSubseq<Seq, I>: TupleLikewhere
Seq: TupleLike,{
// Required methods
fn con_subseq(self) -> Seq;
fn con_subseq_ref(&self) -> Seq::AsRefOutput<'_>;
fn con_subseq_mut(&mut self) -> Seq::AsMutOutput<'_>;
fn swap_con_subseq(&mut self, subseq: &mut Seq);
// Provided method
fn replace_con_subseq(&mut self, subseq: Seq) -> Seq { ... }
}Expand description
Search for contiguous subsequences of tuples.
Unlike Subseq, this trait requires that all elements of the subsequence are
contiguous in the supersequence.
The contiguous subsequence must have one and only one candidate in the supersequence.
Required Methods§
Sourcefn con_subseq(self) -> Seq
fn con_subseq(self) -> Seq
Take out a contiguous subsequence.
Unlike subseq(), this method requires that all elements of the subsequence are
contiguous in the supersequence. Sometimes it can do things that subseq() can’t.
NOTE: The contiguous subsequence must have one and only one candidate in the supersequence.
Add a type annotation to the contiguous subsequence to let con_subseq() know.
Hint: The TupleLike trait provides the con_subseq() method as the wrapper
for this con_subseq() method.
§Example
use tuplez::{tuple, TupleLike, tuple_t};
let tup = tuple!(12, "hello", 24, true, false);
// For `subseq`, 4 candidates available:
// `(12, true)`,
// `(12, false)`,
// `(24, true)`,
// `(24, false)`,
// so this cannot be compiled.
// let subseq: tuple_t!(i32, bool) = tup.subseq();
// But for `con_subseq`,only `(24, true)` is a candidate.
let subseq: tuple_t!(i32, bool) = tup.con_subseq();
assert_eq!(subseq, tuple!(24, true));Sourcefn con_subseq_ref(&self) -> Seq::AsRefOutput<'_>
fn con_subseq_ref(&self) -> Seq::AsRefOutput<'_>
Similar to con_subseq(),
but all its elements are immutable references to the supersequence’s elements.
NOTE: The contiguous subsequence must have one and only one candidate in the supersequence.
Rust is almost impossible to infer generic types by the return type annotation, so you need to call it like:
Hint: The TupleLike trait provides the con_subseq_ref() method
as the wrapper for this con_subseq_ref() method.
use tuplez::{tuple, TupleLike, tuple_t};
let tup = tuple!(12, "hello", vec![1, 2, 3], 24, 3.14, true);
let subseq = tup.con_subseq_ref::<tuple_t!(i32, f32), _>();
assert_eq!(subseq, tuple!(&24, &3.14));Sourcefn con_subseq_mut(&mut self) -> Seq::AsMutOutput<'_>
fn con_subseq_mut(&mut self) -> Seq::AsMutOutput<'_>
Similar to con_subseq(),
but all its elements are mutable references to the supersequence’s elements.
NOTE: The contiguous subsequence must have one and only one candidate in the supersequence.
Rust is almost impossible to infer generic types by the return type annotation, so you need to call it like:
Hint: The TupleLike trait provides the con_subseq_mut() method
as the wrapper for this con_subseq_mut() method.
use tuplez::{get, tuple, TupleLike, tuple_t};
let mut tup = tuple!(12, "hello", vec![1, 2, 3], "world", 24, 36);
let subseq = tup.con_subseq_mut::<tuple_t!(&'static str, i32), _>();
*get!(subseq; 0) = "rust";
*get!(subseq; 1) = 0;
assert_eq!(tup, tuple!(12, "hello", vec![1, 2, 3], "rust", 0, 36));Sourcefn swap_con_subseq(&mut self, subseq: &mut Seq)
fn swap_con_subseq(&mut self, subseq: &mut Seq)
Swap elements with a contiguous subsequence.
Unlike swap_subseq(), this method requires that all
elements of the subsequence are contiguous in the supersequence.
Sometimes it can do things that swap_subseq() can’t.
NOTE: The contiguous subsequence must have one and only one candidate in the supersequence.
Hint: The TupleLike trait provides the swap_con_subseq() method
as the wrapper for this swap_con_subseq() method.
§Example
use tuplez::{tuple, TupleLike};
let mut tup = tuple!(1, Some("hello"), 2, Some(()), 3.14, 3);
let mut tup2 = tuple!(4, None::<()>);
tup.swap_con_subseq(&mut tup2);
assert_eq!(tup, tuple!(1, Some("hello"), 4, None::<()>, 3.14, 3));
assert_eq!(tup2, tuple!(2, Some(())));Provided Methods§
Sourcefn replace_con_subseq(&mut self, subseq: Seq) -> Seq
fn replace_con_subseq(&mut self, subseq: Seq) -> Seq
Replace elements with a contiguous subsequence.
Unlike replace_subseq(), this method requires that
all elements of the subsequence are contiguous in the supersequence.
Sometimes it can do things that replace_subseq() can’t.
NOTE: The contiguous subsequence must have one and only one candidate in the supersequence.
It returns a contiguous subsequence consisting of the replaced elements.
Hint: If you don’t want to consume the input tuple,
then what you are looking for might be swap_con_subseq().
Hint: The TupleLike trait provides the replace_con_subseq() method
as the wrapper for this replace_con_subseq() method.
§Example
use tuplez::{tuple, TupleLike};
let mut tup = tuple!(1, Some("hello"), 2, Some(()), 3.14, 3);
let replaced = tup.replace_con_subseq(tuple!(4, None::<()>));
assert_eq!(tup, tuple!(1, Some("hello"), 4, None::<()>, 3.14, 3));
assert_eq!(replaced, tuple!(2, Some(())));Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.