SubseqMapReplace

Trait SubseqMapReplace 

Source
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§

Source

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§

Source

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.

Implementors§

Source§

impl<F> SubseqMapReplace<Unit, F, Complete> for Unit

Source§

impl<First, Other1, Other2, F, I> SubseqMapReplace<Tuple<First, Other2>, F, Used<I>> for Tuple<First, Other1>
where Other1: TupleLike + SubseqMapReplace<Other2, <F as Mapper<First>>::NextMapper, I>, Other2: TupleLike, F: Mapper<First>,

Source§

type MapReplaceOutput = Tuple<<F as Mapper<First>>::Output, <Other1 as SubseqMapReplace<Other2, <F as Mapper<First>>::NextMapper, I>>::MapReplaceOutput>

Source§

impl<First, Other, T, F, I> SubseqMapReplace<T, F, Unused<I>> for Tuple<First, Other>
where T: TupleLike, Other: TupleLike + SubseqMapReplace<T, F, I>,