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
use std::borrow::Cow;

use secrecy::{Secret, Zeroize};

use crate::{registry, InputType, InputValueError, InputValueResult, Type, Value};

impl<T: Type + Zeroize> Type for Secret<T> {
    fn type_name() -> Cow<'static, str> {
        T::type_name()
    }

    fn qualified_type_name() -> String {
        T::qualified_type_name()
    }

    fn create_type_info(registry: &mut registry::Registry) -> String {
        T::create_type_info(registry)
    }
}

impl<T: InputType + Zeroize> InputType for Secret<T> {
    fn parse(value: Option<Value>) -> InputValueResult<Self> {
        T::parse(value)
            .map(Secret::new)
            .map_err(InputValueError::propagate)
    }

    fn to_value(&self) -> Value {
        Value::Null
    }
}