async-graphql/src/types/external/secrecy.rs

36 lines
859 B
Rust
Raw Normal View History

2021-05-11 00:48:54 +00:00
use std::borrow::Cow;
use secrecy::{ExposeSecret, Secret, Zeroize};
2021-05-11 00:48:54 +00:00
use crate::{registry, InputType, InputValueError, InputValueResult, Value};
2021-05-11 00:48:54 +00:00
impl<T: InputType + Zeroize> InputType for Secret<T> {
type RawValueType = T::RawValueType;
2021-05-11 00:48:54 +00:00
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)
}
fn parse(value: Option<Value>) -> InputValueResult<Self> {
2021-05-11 03:00:29 +00:00
T::parse(value)
.map(Secret::new)
.map_err(InputValueError::propagate)
2021-05-11 00:48:54 +00:00
}
fn to_value(&self) -> Value {
Value::Null
}
fn as_raw_value(&self) -> Option<&Self::RawValueType> {
self.expose_secret().as_raw_value()
}
2021-05-11 00:48:54 +00:00
}