-
Notifications
You must be signed in to change notification settings - Fork 20
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
Owned [NamedField] for Fields #62
Comments
@sunng87 just to clarify here, is it the slice that should be owned, or the |
@hawkw I think I need for both. I'm trying to construct a Type like this works best for my scenario: pub enum Fields<'a> {
/// Named fields
Named(&'a [NamedField<'a>]),
OwnedNamed(Vec<OwnedNamedField>), // where OwnedNamedField hold an owned String instead of str
/// Unnamed (positional) fields or unit
Unnamed,
} |
Right, I'm looking into a possible change like this. But, I'm not totally sure if I understand why this change is necessary. If you have a |
That sounds reasonable. It has been a while since last time I'm running into this issue. Let me check my feature branch again to refresh my context about this. |
@sunng87 let me know if that solution works out for you; I'd like to get this issue figured out soon, because if we do add code to make owned named fields possible, we would probably have to make some breaking changes, and it would be nice to figure out what's necessary here before releasing 0.1. |
Sorry for late response. I may still have issue with current impl<'a> Structable for Map<String, Json> {
fn definition(&'a self) -> StructDef<'a> {
let field_defs: Vec<NamedField<'a>> = Vec::new();
// add field names
let fields = Fields::Named(&field_defs);
let def = StructDef::Dynamic {
name: "Json",
fields,
};
def
}
} There are two issues from this piece of code:
|
Hmm, I see why you can't borrow the fields here, so you're right that an owned variant might be necessary. Thanks for the example! |
Another suggestion is to make |
At some point, I'd say that the type isn't a structable but a mappable. I think it would be fair to add some additional trait fns that make it easier to work w/ json objects. Eg. |
The only concern with |
The current signature of
Fields::Named
hold a borrowed slice ofNamedField
. As far as I can tell, it's designed for'static
definition of rust structs. This makes it difficult to define dynamicStructable
for a map like we talked in #53 .Perhaps we can make it a
Cow
for the dynamic scenario.The text was updated successfully, but these errors were encountered: