use serde::Deserialize;
#[derive(Clone, Debug, Deserialize)]
pub struct Prisecter {
pub pri: f64,
pub sec: f64,
pub ter: f64,
}
impl Prisecter {
pub fn to_array(&self) -> [f64; 3] {
[self.pri, self.sec, self.ter]
}
}
impl AsRef<Prisecter> for Prisecter {
fn as_ref(&self) -> &Self {
self
}
}
#[derive(Clone, Debug)]
pub enum Bound {
After([f64; 3]),
Before([f64; 3]),
}
impl Bound {
pub(crate) fn to_query_param(&self) -> (String, String) {
match self {
Bound::After(b) => ("after".to_string(), format!("{}:{}:{}", b[0], b[1], b[2])),
Bound::Before(b) => ("before".to_string(), format!("{}:{}:{}", b[0], b[1], b[2])),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn prisecter_to_array_converts_to_array() {
let prisecter = Prisecter {
pri: 1.0,
sec: 2.0,
ter: 3.0,
};
assert_eq!(prisecter.to_array(), [1.0, 2.0, 3.0]);
}
#[test]
fn prisecter_as_ref_converts_to_ref() {
let prisecter = Prisecter {
pri: 1.0,
sec: 2.0,
ter: 3.0,
};
let _ref_prisecter: &Prisecter = prisecter.as_ref();
}
#[test]
fn bound_after_to_query_param_converts_into_query_param() {
let bound = Bound::After([12345.678, 0.0, 0.0]);
assert_eq!(
bound.to_query_param(),
("after".to_string(), "12345.678:0:0".to_string())
);
}
#[test]
fn bound_before_to_query_param_converts_into_query_param() {
let bound = Bound::Before([12345.678, 0.0, 0.0]);
assert_eq!(
bound.to_query_param(),
("before".to_string(), "12345.678:0:0".to_string())
);
}
}