Skip to main content

logic_eval/parse/
common.rs

1use crate::Atom;
2use core::fmt::{self, Display};
3
4pub trait Intern {
5    type Interned<'a>: Atom
6    where
7        Self: 'a;
8
9    fn intern_str(&self, s: &str) -> Self::Interned<'_>;
10
11    fn intern_formatted_str<T: Display + ?Sized>(
12        &self,
13        value: &T,
14        upper_size: usize,
15    ) -> Result<Self::Interned<'_>, fmt::Error>;
16}
17
18impl Intern for any_intern::DroplessInterner {
19    type Interned<'a>
20        = any_intern::Interned<'a, str>
21    where
22        Self: 'a;
23
24    fn intern_str(&self, s: &str) -> Self::Interned<'_> {
25        self.intern(s)
26    }
27
28    fn intern_formatted_str<T: Display + ?Sized>(
29        &self,
30        value: &T,
31        upper_size: usize,
32    ) -> Result<Self::Interned<'_>, fmt::Error> {
33        <Self>::intern_formatted_str(self, value, upper_size)
34    }
35}
36
37impl Intern for any_intern::Interner {
38    type Interned<'a>
39        = any_intern::Interned<'a, str>
40    where
41        Self: 'a;
42
43    fn intern_str(&self, s: &str) -> Self::Interned<'_> {
44        self.intern_dropless(s)
45    }
46
47    fn intern_formatted_str<T: Display + ?Sized>(
48        &self,
49        value: &T,
50        upper_size: usize,
51    ) -> Result<Self::Interned<'_>, fmt::Error> {
52        <Self>::intern_formatted_str(self, value, upper_size)
53    }
54}
55
56pub type StrInterner = any_intern::DroplessInterner;
57pub type InternedStr<'int> = any_intern::Interned<'int, str>;