Trait TypedOpaque

Source
pub trait TypedOpaque:
    Opaque
    + Clone
    + PartialEq
    + Debug
    + Display
    + Send
    + Sync {
    // Required method
    fn opaque_type() -> OpaqueType;
}
Expand description

Trait for opaque types with additional type constraints.

This trait extends Opaque with additional requirements that enable more sophisticated operations on opaque values. It adds:

  • Value equality: Types can be compared for equality
  • Cloning: Efficient cloning without heap allocation
  • Enhanced type safety: Stronger compile-time guarantees

§When to Use TypedOpaque

Use TypedOpaque when your opaque type needs:

  • Equality comparisons in CEL expressions
  • Participation in hash-based collections
  • Advanced type checking and validation
  • Integration with CEL’s type inference system

§Additional Requirements

Beyond Opaque, this trait requires:

  • Clone: Direct cloning (not just through trait objects)
  • PartialEq: Value equality comparison
  • All the traits required by Opaque

§Examples

§Comparable Opaque Type

use cel_cxx::Opaque;

#[derive(Opaque, Debug, Clone, PartialEq, Eq, Hash)]
struct ProductId(String);

impl std::fmt::Display for ProductId {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "ProductId({})", self.0)
    }
}

// All necessary traits are automatically implemented by the derive macro

Required Methods§

Source

fn opaque_type() -> OpaqueType

Returns the static opaque type for this value type.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§