scsys_traits/ops/
map.rs

1/*
2    appellation: map <module>
3    authors: @FL03
4*/
5/// [`Map`] is a trait that allows for mapping over a reference to a type `T` by applying a
6/// function [`F`](FnOnce) to it, producing a new type `U`. The result is wrapped in a
7/// container type defined by the implementor of the trait.
8pub trait Map<T> {
9    /// The associated type `Cont` is a higher-kinded type that represents the container
10    /// that will hold the result of the mapping operation.
11    type Cont<_T: ?Sized>;
12
13    fn map<U, F>(&self, rhs: F) -> Self::Cont<U>
14    where
15        F: FnOnce(&T) -> U;
16}
17/// A the [`MapOnce`] trait is similar to [`Map`], but it consumes the instance instead of
18/// borrowing it;
19pub trait MapOnce<T> {
20    type Cont<_T: ?Sized>;
21
22    fn mapc<U, F>(self, rhs: F) -> Self::Cont<U>
23    where
24        F: FnOnce(T) -> U;
25}
26
27pub trait MapInplace<T> {
28    type Cont<_T: ?Sized>;
29
30    fn map_inplace<F>(&mut self, rhs: F) -> &mut Self::Cont<T>
31    where
32        F: FnMut(&mut T);
33}