morethantext/src/router.rs

55 lines
1.3 KiB
Rust
Raw Normal View History

2025-12-26 15:03:42 -05:00
use crate::{message::Action, name::NameType};
use uuid::Uuid;
2025-12-26 13:48:02 -05:00
#[derive(Clone, Debug, Eq, Hash)]
pub enum Include<T> {
All,
Just(T),
}
impl<T: PartialEq> PartialEq for Include<T> {
fn eq(&self, other: &Self) -> bool {
match self {
Include::All => true,
Include::Just(data) => match other {
Include::All => true,
Include::Just(other_data) => data == other_data,
},
}
}
}
#[cfg(test)]
mod includes {
use super::*;
#[test]
fn does_all_equal_evberything() {
let a: Include<isize> = Include::All;
let b: Include<isize> = Include::Just(5);
let c: Include<isize> = Include::Just(7);
assert!(a == a, "all should equal all");
2025-12-26 15:03:42 -05:00
assert!(a == b, "all should equal just");
assert!(b == a, "just should equal all");
assert!(b == b, "same just should equal");
assert!(b != c, "different justs do not equal");
}
}
#[derive(Clone, Debug)]
pub struct Path {
pub msg_id: Include<Uuid>,
pub doc: Include<NameType>,
pub action: Include<Action>,
}
impl Path {
pub fn new(id: Include<Uuid>, doc: Include<NameType>, action: Include<Action>) -> Self {
Self {
msg_id: id,
doc: doc,
action: action,
}
2025-12-26 13:48:02 -05:00
}
}