#[derive(Debug, Clone)]
pub struct KeywordResource {
pub page: usize,
pub font_id: Option<String>,
pub font_size: Option<f64>,
}
impl KeywordResource {
#[must_use]
pub fn new(page: usize) -> Self {
Self {
page,
font_id: None,
font_size: None,
}
}
#[must_use]
pub fn with_font_id(mut self, font_id: impl Into<String>) -> Self {
self.font_id = Some(font_id.into());
self
}
#[must_use]
pub fn with_font_size(mut self, size: f64) -> Self {
self.font_size = Some(size);
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_keyword_resource_new() {
let res = KeywordResource::new(1);
assert_eq!(res.page, 1);
assert!(res.font_id.is_none());
assert!(res.font_size.is_none());
}
#[test]
fn test_keyword_resource_with_font() {
let res = KeywordResource::new(2)
.with_font_id("font_0")
.with_font_size(12.0);
assert_eq!(res.font_id.as_deref(), Some("font_0"));
assert!((res.font_size.unwrap() - 12.0).abs() < f64::EPSILON);
}
}