When working with Context objects, extracting values requires verbose pattern matching through the internal AST structure. This creates unnecessary boilerplate code and complexity for a common operation.
Proposed Solution
Add a get convenience method to Context that would simplify value extraction:
impl Context {
/// Retrieves a value from the Context by its key.
pub fn get(&self, key: &str) -> Option<&Value>
}
// Current approach requires complex pattern matching
// New approach would be:
let ray_id = request
.context()
.and_then(|ctx| ctx.get("rayId"))
.map(|id| id.to_string())
.unwrap_or_else(|| "default_id".to_string());
Let me know if you'd like any adjustments to the issue title or description!
Describe the improvement you'd like to request
Problem
When working with Context objects, extracting values requires verbose pattern matching through the internal AST structure. This creates unnecessary boilerplate code and complexity for a common operation.
Proposed Solution
Add a
get
convenience method toContext
that would simplify value extraction:Let me know if you'd like any adjustments to the issue title or description!
Open PR: https://github.com/cedar-policy/cedar/pull/1318
Describe alternatives you've considered
No response
Additional context
No response
Is this something that you'd be interested in working on?