1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::fmt::Display;
use std::fmt::Error;
use std::fmt::Formatter;

/// Details of an object in an OSTree repo. It contains information about if
/// the object is "loose", and contains a list of pack file checksums in which
/// this object appears.
#[derive(Debug)]
pub struct ObjectDetails {
    loose: bool,
    object_appearances: Vec<String>,
}

impl ObjectDetails {
    /// Create a new `ObjectDetails` from a serialized representation.
    pub fn new_from_variant(variant: glib::Variant) -> Option<ObjectDetails> {
        let deserialize = variant.get::<(bool, Vec<String>)>()?;
        Some(ObjectDetails {
            loose: deserialize.0,
            object_appearances: deserialize.1,
        })
    }

    /// is object available "loose"
    pub fn is_loose(&self) -> bool {
        self.loose
    }

    /// Provide list of pack file checksums in which the object appears
    pub fn appearances(&self) -> &Vec<String> {
        &self.object_appearances
    }
}

impl Display for ObjectDetails {
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
        write!(
            f,
            "Object is {} and appears in {} checksums",
            if self.loose { "loose" } else { "not loose" },
            self.object_appearances.len()
        )
    }
}