zvariant_utils/signature/
child.rs

1use std::ops::Deref;
2
3use super::Signature;
4
5/// A child signature of a container signature.
6#[derive(Debug, Clone)]
7pub enum Child {
8    /// A static child signature.
9    Static { child: &'static Signature },
10    /// A dynamic child signature.
11    Dynamic { child: Box<Signature> },
12}
13
14impl Child {
15    /// The underlying child `Signature`.
16    pub const fn signature(&self) -> &Signature {
17        match self {
18            Child::Static { child } => child,
19            Child::Dynamic { child } => child,
20        }
21    }
22
23    /// The length of the child signature in string form.
24    pub const fn string_len(&self) -> usize {
25        self.signature().string_len()
26    }
27}
28
29impl Deref for Child {
30    type Target = Signature;
31
32    fn deref(&self) -> &Self::Target {
33        self.signature()
34    }
35}
36
37impl From<Box<Signature>> for Child {
38    fn from(child: Box<Signature>) -> Self {
39        Child::Dynamic { child }
40    }
41}
42
43impl From<Signature> for Child {
44    fn from(child: Signature) -> Self {
45        Child::Dynamic {
46            child: Box::new(child),
47        }
48    }
49}
50
51impl From<&'static Signature> for Child {
52    fn from(child: &'static Signature) -> Self {
53        Child::Static { child }
54    }
55}