Add get_string convenience method to Context for string value extraction
Closed this issue · 0 comments
tamas-jozsa commented
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 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!
Open PR: #1318
Describe alternatives you've considered
No response
Additional context
No response
Is this something that you'd be interested in working on?
- 👋 I may be able to implement this internal improvement
-
⚠️ This feature might incur a breaking change