Trait for user-defined opaque values stored inside [`Value::Opaque`]. Implement this trait for types that should participate in CEL evaluation as opaque/user-defined values. An opaque value: - must report a stable runtime type name via [`Opaque::runtime_type_name`]; - participates in equality via the blanket [`OpaqueEq`] implementation; - can be formatted via [`AsDebug`]; - must be thread-safe (`
| 384 | /// assert_eq!(a, b); |
| 385 | /// ``` |
| 386 | pub trait Opaque: Any + OpaqueEq + AsDebug + Send + Sync { |
| 387 | /// Returns a stable, fully-qualified type name for this value's runtime type. |
| 388 | /// |
| 389 | /// This name is used to check type compatibility before attempting downcasts |
| 390 | /// during equality checks and other operations. It should be stable across |
| 391 | /// versions and unique within your application or library (e.g., a package |
| 392 | /// qualified name like `my.pkg.Type`). |
| 393 | fn runtime_type_name(&self) -> &str; |
| 394 | |
| 395 | /// Optional JSON representation (requires the `json` feature). |
| 396 | /// |
| 397 | /// The default implementation returns `None`, indicating that the value |
| 398 | /// cannot be represented as JSON. |
| 399 | #[cfg(feature = "json")] |
| 400 | fn json(&self) -> Option<serde_json::Value> { |
| 401 | None |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | impl dyn Opaque { |
| 406 | pub fn downcast_ref<T: Any>(&self) -> Option<&T> { |
no outgoing calls
no test coverage detected