Skip to main content

cel_cxx/values/impls/
struct.rs

1use crate::{types::*, values::*};
2
3impl IntoValue for StructValue {
4    fn into_value(self) -> Value {
5        Value::Struct(self)
6    }
7}
8
9impl TypedValue for StructValue {
10    /// Returns `Dyn` because `TypedValue` is a static trait method with no access
11    /// to the instance's `type_name`. The actual message type is resolved at the
12    /// FFI layer during evaluation via the DescriptorPool.
13    fn value_type() -> ValueType {
14        ValueType::Dyn
15    }
16}
17
18impl FromValue for StructValue {
19    type Output<'a> = StructValue;
20
21    fn from_value<'a>(value: &'a Value) -> Result<Self::Output<'a>, FromValueError> {
22        match value {
23            Value::Struct(s) => Ok(s.clone()),
24            _ => Err(FromValueError::new(value.clone(), "struct")),
25        }
26    }
27}
28
29impl FromValue for &StructValue {
30    type Output<'a> = &'a StructValue;
31
32    fn from_value<'a>(value: &'a Value) -> Result<Self::Output<'a>, FromValueError> {
33        match value {
34            Value::Struct(s) => Ok(s),
35            _ => Err(FromValueError::new(value.clone(), "struct")),
36        }
37    }
38}