1#![expect(clippy::inline_always)]
2
3use crate::{Allocator, Box};
4
5pub trait FromIn<'a, T>: Sized {
10    fn from_in(value: T, allocator: &'a Allocator) -> Self;
12}
13
14pub trait IntoIn<'a, T>: Sized {
18    fn into_in(self, allocator: &'a Allocator) -> T;
20}
21
22impl<'a, T> FromIn<'a, T> for T {
24    #[inline(always)]
25    fn from_in(t: T, _: &'a Allocator) -> T {
26        t
27    }
28}
29
30impl<'a, T, U> IntoIn<'a, U> for T
32where
33    U: FromIn<'a, T>,
34{
35    #[inline]
36    fn into_in(self, allocator: &'a Allocator) -> U {
37        U::from_in(self, allocator)
38    }
39}
40
41impl<'a> FromIn<'a, String> for &'a str {
44    #[inline(always)]
45    fn from_in(value: String, allocator: &'a Allocator) -> Self {
46        allocator.alloc_str(value.as_str())
47    }
48}
49
50impl<'a, T> FromIn<'a, T> for Box<'a, T> {
51    #[inline(always)]
52    fn from_in(value: T, allocator: &'a Allocator) -> Self {
53        Box::new_in(value, allocator)
54    }
55}
56
57impl<'a, T> FromIn<'a, Option<T>> for Option<Box<'a, T>> {
58    #[inline(always)]
59    fn from_in(value: Option<T>, allocator: &'a Allocator) -> Self {
60        value.map(|it| Box::new_in(it, allocator))
61    }
62}