av_data/
value.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! Option values definitions.

use crate::audiosample::Soniton;
use crate::pixel::Formaton;

use std::convert::From;
use std::sync::Arc;

/// Accepted option values.
#[derive(Debug)]
pub enum Value<'a> {
    /// Signed integer value.
    I64(i64),
    /// Unsigned integer value.
    U64(u64),
    /// Unicode string slice value.
    Str(&'a str),
    /// Boolean value.
    Bool(bool),
    /// Pair of signed integer values.
    Pair(i64, i64),
    /// Image colorspace representation value.
    Formaton(Arc<Formaton>),
    /// Audio format definition value.
    Soniton(Arc<Soniton>),
}

impl<'a> From<i64> for Value<'a> {
    fn from(v: i64) -> Self {
        Value::I64(v)
    }
}

impl<'a> From<u64> for Value<'a> {
    fn from(v: u64) -> Self {
        Value::U64(v)
    }
}

impl<'a> From<&'a str> for Value<'a> {
    fn from(v: &'a str) -> Self {
        Value::Str(v)
    }
}

impl<'a> From<bool> for Value<'a> {
    fn from(v: bool) -> Self {
        Value::Bool(v)
    }
}

impl<'a> From<(i64, i64)> for Value<'a> {
    fn from(v: (i64, i64)) -> Self {
        Value::Pair(v.0, v.1)
    }
}

impl<'a> From<Arc<Formaton>> for Value<'a> {
    fn from(v: Arc<Formaton>) -> Self {
        Value::Formaton(v)
    }
}

impl<'a> From<Arc<Soniton>> for Value<'a> {
    fn from(v: Arc<Soniton>) -> Self {
        Value::Soniton(v)
    }
}

#[cfg(test)]
mod test {
    use super::*;
    use std::fmt::Debug;

    fn p<'a, T>(v: T)
    where
        T: Into<Value<'a>> + Debug,
    {
        println!("{:?}", v);
    }

    #[test]
    fn value_str() {
        p("test");
    }
}