Skip to main content

nanite_docker/instruction/
volume.rs

1use alloc::string::String;
2use alloc::vec::Vec;
3use core::fmt::{Display, Formatter};
4
5/// Represents a `VOLUME` instruction.
6/// ```rust
7/// use nanite_docker::Volume;
8///
9/// let volume = Volume {
10///     volumes: vec!["/var/log".into()],
11/// };
12/// let volume_built = format!("{volume}");
13/// assert_eq!(volume_built, r#"VOLUME ["/var/log"]"#);
14/// ```
15#[derive(Clone, Debug)]
16pub struct Volume {
17    pub volumes: Vec<String>,
18}
19impl Display for Volume {
20    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
21        write!(f, "VOLUME [")?;
22
23        for (i, arg) in self.volumes.iter().enumerate() {
24            if i != 0 {
25                write!(f, ", ")?;
26            }
27            write!(f, r#""{arg}""#)?;
28        }
29
30        write!(f, "]")?;
31
32        Ok(())
33    }
34}