Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_string convenience method to Context for string value extraction #1319

Closed
1 of 2 tasks
tamas-jozsa opened this issue Nov 13, 2024 · 0 comments
Closed
1 of 2 tasks
Labels
internal-improvement Refactoring, minor performance improvement, or other changes that Cedar users may never notice pending-triage The cedar maintainers haven't looked at this yet. Automicaly added to all new issues.

Comments

@tamas-jozsa
Copy link
Contributor

tamas-jozsa commented Nov 13, 2024

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
@tamas-jozsa tamas-jozsa added internal-improvement Refactoring, minor performance improvement, or other changes that Cedar users may never notice pending-triage The cedar maintainers haven't looked at this yet. Automicaly added to all new issues. labels Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal-improvement Refactoring, minor performance improvement, or other changes that Cedar users may never notice pending-triage The cedar maintainers haven't looked at this yet. Automicaly added to all new issues.
Projects
None yet
Development

No branches or pull requests

2 participants