use super::Triplet;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct TripletQuery {
pub index: Option<u32>,
pub type_id: Option<u32>,
pub from: Option<u32>,
pub to: Option<u32>,
}
impl TripletQuery {
pub fn any() -> Self {
Self::default()
}
pub fn new(
index: Option<u32>,
type_id: Option<u32>,
from: Option<u32>,
to: Option<u32>,
) -> Self {
Self {
index,
type_id,
from,
to,
}
}
pub fn by_index(index: u32) -> Self {
Self {
index: Some(index),
..Self::default()
}
}
pub fn by_type(type_id: u32) -> Self {
Self {
type_id: Some(type_id),
..Self::default()
}
}
pub fn by_from(from: u32) -> Self {
Self {
from: Some(from),
..Self::default()
}
}
pub fn by_to(to: u32) -> Self {
Self {
to: Some(to),
..Self::default()
}
}
pub fn matches(&self, triplet: &Triplet) -> bool {
self.index.is_none_or(|index| index == triplet.index)
&& self
.type_id
.is_none_or(|type_id| type_id == triplet.type_id)
&& self.from.is_none_or(|from| from == triplet.from)
&& self.to.is_none_or(|to| to == triplet.to)
}
}