-
Notifications
You must be signed in to change notification settings - Fork 10
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
Object-Entity Mapping (OEM) #72
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Shaobo He <[email protected]>
text/0072-oem.md
Outdated
|
||
Given limited knowledge about Rust macros the proposer has, the design details are subject to significant changes. | ||
|
||
The macros over a Rust type eventually expand to implementations of `Into<Entities>`. In the meantime, they also give rise to implementations of `Into<Value>` for this type. By default, the implementation of `Into<Value` for a type produces an entity `uid` unless the type is annotated with the `#[cedar(transparent)]` clause, where it produces a record. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
produces an entity
uid
unless the type is annotated with the#[cedar(transparent)]
clause
I would rather see this made more explicit. E.g., #[cedar(record)]
or #[cedar(entity)]
, perhaps with the entity case being assumed by default.
This could also support a nice syntax like #[cedar(long)] struct MyLong(i32)
for wrapper types that might exist.
Signed-off-by: Shaobo He <[email protected]>
Thanks for the writeup @shaobo-he-aws! I think this looks like a useful addition to Cedar, but I disagree that it should be an RFC. It's a change to the Rust API rather than the Cedar language, so I think it should remain as an issue in the How do others feel about an RFC vs. issue here? |
I'm afraid that moving it to an issue reduces discussion and eventually makes it buried in the backlog list. |
We've previously done RFCs for other major changes that aren't technically changes to the Cedar language itself, for example, RFC 32 and arguably RFC 8. Similarly, I think there is consensus that partial evaluation itself would have been an RFC except that its development predates the RFC process. I think that this is a major enough change that an RFC is warranted, and particularly since @shaobo-he-aws has already gone to the trouble of writing one up, I think it makes sense to treat it as an RFC. If we didn't already have an RFC writeup and the primary author was pushing hard to keep this an issue instead of an RFC, I could see us maybe making a different decision on RFC vs issue, but since in this case the primary author is welcoming the RFC process, I see no reason to deny that.
Even getting an RFC accepted (into |
What about a trait that would allow an user-provided struct to be borrowed as an entity/context? Something like trait AsEntity {
pub fn uid(&self) -> EntityUID;
pub fn get(&self, attr: &str) -> Option<&AsPartialValue>;
pub fn get_tag(&self, tag: &str) -> Option<&AsPartialValue>;
pub fn ancestors -> Impl<Iterator....
// whatever other things the evaluator could want to know.
} or the same with Result return types. Basically you could implement this trait if you have a type that you know its representing an entity, whatever its internal structure is (it could be a serde_json::Value, your own struct, whatever), and the evaluator could use it to try to view it as one, without necessarily needing to allocate an actual owned 'Entity' structure. At first, this api would be provided by the evaluator in fact aggressively converting to Entity, but later the conversion could be optimized away. This wouldn't of course matter for use over the network, but could make it more seamless to integrate cedar directly to a rust codebase. One might chose to then implement this manually, and the macros originally mentioned in the rfc would implement this too, instead of Into |
This is a good idea. Do you mind writing up a RFC for it? |
I would be happy to, when I find the time. |
The RFC is here: |
Rendered