Skip to main content

merman_render/svg/icon_registry/
pack.rs

1/// One borrowed IconifyJSON collection admitted by an immutable registry build transaction.
2///
3/// The bytes and optional registration name are borrowed only while [`super::IconRegistryBuilder`]
4/// ingests this value. A successful registry owns all validated state and does not retain either
5/// borrow.
6#[derive(Clone, Copy)]
7pub struct IconPack<'a> {
8    json: &'a [u8],
9    registration_name: Option<&'a str>,
10}
11
12impl std::fmt::Debug for IconPack<'_> {
13    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14        formatter
15            .debug_struct("IconPack")
16            .field("json_len", &self.json.len())
17            .field(
18                "registration_name_len",
19                &self.registration_name.map(str::len),
20            )
21            .finish_non_exhaustive()
22    }
23}
24
25impl<'a> IconPack<'a> {
26    pub const fn new(json: &'a [u8]) -> Self {
27        Self {
28            json,
29            registration_name: None,
30        }
31    }
32
33    #[must_use]
34    pub const fn with_registration_name(mut self, registration_name: &'a str) -> Self {
35        self.registration_name = Some(registration_name);
36        self
37    }
38
39    pub const fn json(self) -> &'a [u8] {
40        self.json
41    }
42
43    pub const fn registration_name(self) -> Option<&'a str> {
44        self.registration_name
45    }
46}