lychee_lib/types/
hints.rs1use std::{
5 collections::{BTreeSet, btree_set::IntoIter},
6 fmt::Display,
7 sync::Mutex,
8};
9
10static HINTS: Mutex<BTreeSet<Hint>> = Mutex::new(BTreeSet::new());
12
13#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
16pub struct Hint(String);
17
18impl Display for Hint {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 write!(f, "{}", self.0)
21 }
22}
23
24impl From<String> for Hint {
25 fn from(value: String) -> Self {
26 Self(value)
27 }
28}
29
30impl From<&str> for Hint {
31 fn from(value: &str) -> Self {
32 Self(value.to_owned())
33 }
34}
35
36pub fn add_hint(hint: Hint) {
44 HINTS.lock().unwrap().insert(hint);
45}
46
47#[macro_export]
50macro_rules! hint {
51 ($($arg:tt)*) => {{
52 $crate::add_hint(format!($($arg)*).into());
53 }};
54}
55
56pub fn get_hints() -> IntoIter<Hint> {
62 HINTS.lock().unwrap().clone().into_iter()
63}