pub struct CedarValueMapper { /* private fields */ }Expand description
Mapper for bidirectional JSON ↔ Cedar value conversion.
Provides methods to convert between serde_json::Value and Cedar’s
RestrictedExpression, with support for all Cedar data types including
extension types (IP addresses, decimals).
Implementations§
Source§impl CedarValueMapper
impl CedarValueMapper
Sourcepub fn new_without_auto_detect() -> Self
pub fn new_without_auto_detect() -> Self
Create a mapper with auto-detection of extension types disabled.
Sourcepub fn with_max_size(self, max_size: usize) -> Self
pub fn with_max_size(self, max_size: usize) -> Self
Set the maximum allowed value size in bytes.
A value of 0 means no limit.
Sourcepub fn json_to_cedar(
&self,
value: &Value,
) -> Result<Option<RestrictedExpression>, ValueMappingError>
pub fn json_to_cedar( &self, value: &Value, ) -> Result<Option<RestrictedExpression>, ValueMappingError>
Convert a JSON value to a Cedar RestrictedExpression.
Supports all Cedar primitive types, collections, and extension types. Null values are not supported and will return an error.
Sourcepub fn json_to_cedar_with_type(
&self,
value: &Value,
) -> Result<Option<(RestrictedExpression, CedarType)>, ValueMappingError>
pub fn json_to_cedar_with_type( &self, value: &Value, ) -> Result<Option<(RestrictedExpression, CedarType)>, ValueMappingError>
Convert a JSON value to Cedar, returning the inferred Cedar type.
This is useful when you need both the expression and type information.
Sourcepub fn cedar_to_json(expr_json: &Value) -> Result<Value, ValueMappingError>
pub fn cedar_to_json(expr_json: &Value) -> Result<Value, ValueMappingError>
Convert a Cedar expression back to JSON format.
This is useful for serializing Cedar values for storage or transmission.
Entity references are converted to {"type": "...", "id": "..."} format.
Extension types are converted to {"__extn": {"fn": "...", "arg": "..."}} format.
§Note
This method works with the JSON representation of Cedar values,
not the evaluated result. For evaluated results, use eval_result_to_json.
Sourcepub fn get_nested<'a>(
value: &'a Value,
path: &str,
) -> Result<&'a Value, ValueMappingError>
pub fn get_nested<'a>( value: &'a Value, path: &str, ) -> Result<&'a Value, ValueMappingError>
Access a nested value using dot notation.
Sourcepub fn set_nested(
value: &mut Value,
path: &str,
new_value: Value,
) -> Result<(), ValueMappingError>
pub fn set_nested( value: &mut Value, path: &str, new_value: Value, ) -> Result<(), ValueMappingError>
Set a value at a nested path, creating intermediate objects as needed.
Sourcepub fn detect_extension(value: &str) -> Option<ExtensionValue>
pub fn detect_extension(value: &str) -> Option<ExtensionValue>
Detect if a string value represents a Cedar extension type.
Detects the following extension types:
ipaddr: IP addresses (IPv4/IPv6) and CIDR ranges (e.g., “192.168.1.1”, “10.0.0.0/8”)decimal: Fixed-precision decimals (e.g., “3.14”, “-12.345”)datetime: ISO 8601 / RFC 3339 timestamps (e.g., “2024-10-15T11:35:00Z”)duration: Duration strings (e.g., “2h30m”, “1d12h”, “500ms”)
See: https://docs.cedarpolicy.com/policies/syntax-datatypes.html#datatype-extension
Sourcepub fn is_entity_reference(value: &Value) -> bool
pub fn is_entity_reference(value: &Value) -> bool
Check if a value represents a Cedar entity reference.
Sourcepub fn value_type_name(value: &Value) -> &'static str
pub fn value_type_name(value: &Value) -> &'static str
Get the JSON type name of a value.
Trait Implementations§
Source§impl Clone for CedarValueMapper
impl Clone for CedarValueMapper
Source§fn clone(&self) -> CedarValueMapper
fn clone(&self) -> CedarValueMapper
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CedarValueMapper
impl Debug for CedarValueMapper
Auto Trait Implementations§
impl Freeze for CedarValueMapper
impl RefUnwindSafe for CedarValueMapper
impl Send for CedarValueMapper
impl Sync for CedarValueMapper
impl Unpin for CedarValueMapper
impl UnsafeUnpin for CedarValueMapper
impl UnwindSafe for CedarValueMapper
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request