use crate::proto;
#[derive(Debug, Clone)]
pub struct Input {
pub query: String,
pub range_lb: u16,
pub range_ub: u16,
}
impl Input {
pub fn new(query: impl Into<String>) -> Self {
let range = SelectionRange::end();
Self {
query: query.into(),
range_lb: range.lower_bound,
range_ub: range.upper_bound,
}
}
#[must_use = "builder method consumes self"]
pub fn select(mut self, sel: SelectionRange) -> Self {
self.range_lb = sel.lower_bound;
self.range_ub = sel.lower_bound;
self
}
#[must_use = "builder method consumes self"]
pub(crate) fn into_proto(self) -> proto::Input {
proto::Input {
query: self.query,
range_lb: u32::from(self.range_lb),
range_ub: u32::from(self.range_ub),
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct SelectionRange {
lower_bound: u16,
upper_bound: u16,
}
impl SelectionRange {
pub fn at(index: u16) -> Self {
Self {
lower_bound: index,
upper_bound: index,
}
}
pub fn all() -> Self {
Self {
lower_bound: 0,
upper_bound: u16::MAX,
}
}
pub fn start() -> Self {
Self::at(0)
}
pub fn end() -> Self {
Self::at(u16::MAX)
}
}