easydoc_writer/
doc_image.rs1use std::path::PathBuf;
4
5pub struct DocImage {
7 pub path: PathBuf,
9 pub(crate) width: Option<u32>,
11 pub(crate) height: Option<u32>,
13 alt_text: Option<String>,
14}
15
16impl DocImage {
17 #[must_use]
19 pub fn new(path: impl Into<PathBuf>) -> Self {
20 Self {
21 path: path.into(),
22 width: None,
23 height: None,
24 alt_text: None,
25 }
26 }
27
28 #[must_use]
30 pub fn width(mut self, w: u32) -> Self {
31 self.width = Some(w);
32 self
33 }
34
35 #[must_use]
37 pub fn height(mut self, h: u32) -> Self {
38 self.height = Some(h);
39 self
40 }
41
42 #[must_use]
44 pub fn alt_text(mut self, text: impl Into<String>) -> Self {
45 self.alt_text = Some(text.into());
46 self
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn doc_image_builder() {
56 let img = DocImage::new("/tmp/test.png")
57 .width(100)
58 .height(200)
59 .alt_text("test image");
60 assert_eq!(img.path, std::path::PathBuf::from("/tmp/test.png"));
61 assert_eq!(img.width, Some(100));
62 assert_eq!(img.height, Some(200));
63 }
64}