pub trait SubseqMapReplace<Seq, F, I>: Subseq<Seq, I>where
Seq: TupleLike,{
type MapReplaceOutput: TupleLike;
// Required method
fn map_replace_subseq(self, f: F) -> Self::MapReplaceOutput;
}
Expand description
Replace elements of a specific subsequence to another sequence that may be of different element types.
Required Associated Types§
Sourcetype MapReplaceOutput: TupleLike
type MapReplaceOutput: TupleLike
The type of tuple that replace elements of a specific subsequence to another sequence that may be of different element types.
Required Methods§
Sourcefn map_replace_subseq(self, f: F) -> Self::MapReplaceOutput
fn map_replace_subseq(self, f: F) -> Self::MapReplaceOutput
Replace elements of specific subsequence with another sequence that may be of different element types.
The elements of new sequence is generated from the user-defined mapper.
Check out Mapper
’s documentation page to learn how to build a mapper.
Hint: The TupleLike
trait provides the map_replace_subseq()
method as the wrapper for this map_replace_subseq()
method.
§Example
use std::fmt::Debug;
use tuplez::{mapper, tuple, TupleLike, tuple_t};
let tup = tuple!(1, 3.14, "hello", [1, 2, 3]);
let result = tup.map_replace_subseq::<tuple_t!(f64, [i32; 3]), _, _>(mapper! {
|x: f64| -> i32 { x as i32 }
<T: Debug, const N: usize> |x: [T; N]| -> String { format!("{x:?}") }
});
assert_eq!(result, tuple!(1, 3, "hello", "[1, 2, 3]".to_string()))
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.