use std::path::PathBuf;
pub struct DocImage {
pub path: PathBuf,
pub(crate) width: Option<u32>,
pub(crate) height: Option<u32>,
alt_text: Option<String>,
}
impl DocImage {
#[must_use]
pub fn new(path: impl Into<PathBuf>) -> Self {
Self {
path: path.into(),
width: None,
height: None,
alt_text: None,
}
}
#[must_use]
pub fn width(mut self, w: u32) -> Self {
self.width = Some(w);
self
}
#[must_use]
pub fn height(mut self, h: u32) -> Self {
self.height = Some(h);
self
}
#[must_use]
pub fn alt_text(mut self, text: impl Into<String>) -> Self {
self.alt_text = Some(text.into());
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn doc_image_builder() {
let img = DocImage::new("/tmp/test.png")
.width(100)
.height(200)
.alt_text("test image");
assert_eq!(img.path, std::path::PathBuf::from("/tmp/test.png"));
assert_eq!(img.width, Some(100));
assert_eq!(img.height, Some(200));
}
}