zvariant_utils/signature/
child.rs

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
45
46
47
48
49
50
51
52
53
54
55
56
use std::ops::Deref;

use super::Signature;

/// A child signature of a container signature.
#[derive(Debug, Clone)]
pub enum Child {
    /// A static child signature.
    Static { child: &'static Signature },
    /// A dynamic child signature.
    Dynamic { child: Box<Signature> },
}
static_assertions::assert_impl_all!(Child: Send, Sync, Unpin);

impl Child {
    /// The underlying child `Signature`.
    pub const fn signature(&self) -> &Signature {
        match self {
            Child::Static { child } => child,
            Child::Dynamic { child } => child,
        }
    }

    /// The length of the child signature in string form.
    pub const fn string_len(&self) -> usize {
        self.signature().string_len()
    }
}

impl Deref for Child {
    type Target = Signature;

    fn deref(&self) -> &Self::Target {
        self.signature()
    }
}

impl From<Box<Signature>> for Child {
    fn from(child: Box<Signature>) -> Self {
        Child::Dynamic { child }
    }
}

impl From<Signature> for Child {
    fn from(child: Signature) -> Self {
        Child::Dynamic {
            child: Box::new(child),
        }
    }
}

impl From<&'static Signature> for Child {
    fn from(child: &'static Signature) -> Self {
        Child::Static { child }
    }
}