Skip to main content

rstm_core/rules/traits/
convert.rs

1/*
2    Appellation: convert <module>
3    Created At: 2025.12.15:21:29:39
4    Contrib: @FL03
5*/
6use crate::{Direction, Head, Tail};
7
8/// Converts to a [`Head`] by reference.
9pub trait AsHead<Q, A> {
10    fn as_head(&self) -> Head<Q, A>;
11}
12/// Consumes the caller to convert it into a [`Head`].
13pub trait IntoHead<Q, A> {
14    fn into_head(self) -> Head<Q, A>;
15}
16
17/// Converts a type into a [`Tail`] by reference.
18pub trait AsTail<Q, A> {
19    fn as_tail(&self) -> Tail<Q, A>;
20}
21/// A consuming trait for converting a type into a [`Tail`].
22pub trait IntoTail<Q, A> {
23    fn into_tail(self) -> Tail<Q, A>;
24}
25/// [`IntoDirection`] is a simple conversion trait for consuming types to turn into a [`Direction`].
26pub trait IntoDirection {
27    fn into_direction(self) -> Direction;
28}
29/*
30 ************* Implementations *************
31*/
32impl<T> IntoDirection for T
33where
34    T: Into<Direction>,
35{
36    fn into_direction(self) -> Direction {
37        self.into()
38    }
39}
40
41impl<Q, A, T> IntoHead<Q, A> for T
42where
43    T: Into<Head<Q, A>>,
44{
45    fn into_head(self) -> Head<Q, A> {
46        self.into()
47    }
48}
49
50impl<Q, A, T> IntoTail<Q, A> for T
51where
52    T: Into<Tail<Q, A>>,
53{
54    fn into_tail(self) -> Tail<Q, A> {
55        self.into()
56    }
57}