contained_core/traits/wrapper.rs
1/*
2 Appellation: wrapper <module>
3 Created At: 2026.01.20:14:40:06
4 Contrib: @FL03
5*/
6
7/// The [`Wrapper`] trait established a higher-kinded interface for single-value containers.
8pub trait Wrapper<T> {
9 type Cont<U>: ?Sized;
10
11 /// returns a reference to the inner value
12 fn get(&self) -> &T;
13 /// returns a view of the container containing an immutable reference to the inner value
14 fn view(&self) -> Self::Cont<&T>;
15}
16/// The [`WrapperMut`] trait extends the [`Wrapper`] trait to provide mutable access to the
17/// inner value.
18pub trait WrapperMut<T>: Wrapper<T> {
19 /// returns a mutable reference to the inner value
20 fn get_mut(&mut self) -> &mut T;
21 /// returns a view of the container containing a mutable reference to the inner value
22 fn view_mut(&mut self) -> Self::Cont<&mut T>;
23}
24
25impl<T> Wrapper<T> for T {
26 type Cont<U> = U;
27
28 fn get(&self) -> &T {
29 self
30 }
31
32 fn view(&self) -> Self::Cont<&T> {
33 self
34 }
35}