rspace_traits/impls/
impl_container.rs

1/*
2    Appellation: impl_container <module>
3    Created At: 2025.12.26:19:32:27
4    Contrib: @FL03
5*/
6use crate::container::{Container, ContainerMap};
7use crate::ops::Apply;
8use crate::space::RawSpace;
9
10impl<S, T> Container<T> for S
11where
12    S: RawSpace<Elem = T>,
13{
14    type Cont<V> = S;
15}
16
17impl<S, T> ContainerMap<T> for S
18where
19    S: Container<T, Cont<T> = S>,
20    S::Cont<T>: RawSpace<Elem = T>,
21{
22    fn map<F, X>(&self, f: F) -> Self::Cont<X>
23    where
24        Self::Cont<T>: Apply<F, Output = Self::Cont<X>>,
25        Self::Cont<X>: Sized,
26    {
27        <Self::Cont<T> as Apply<F>>::apply(self, f)
28    }
29}
30
31impl<T> Container<T> for [T] {
32    type Cont<U> = [U];
33}
34
35#[allow(unused_macros)]
36macro_rules! container {
37    (@impl $trait:ident<$T:ident> for $($cont:ident)::*<$($U:ident),+ $(,)?>) => {
38        paste::paste! {
39            impl<$($U),+> $trait<$T> for $($cont)::*<$($U),+> {
40                type Cont<[<_ $T>]> = $($cont)::*<[<_ $T>]>;
41            }
42
43        }
44    };
45    (impl $trait:ident<$T:ident> for {$($($cont:ident)::*<$($U:ident),+ $(,)?>),* $(,)?}) => {
46        $(container!{ @impl $trait<$T> for $($cont)::*<$($U),+>})*
47    };
48}