-
-
Notifications
You must be signed in to change notification settings - Fork 113
Implemented Revamped Object Model #148
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
Conversation
Other potential names I made up:
|
Why not just Will look into making use of this later on today and report back. |
A few notes from making use of this:
|
Also, I haven't investigated further, but I believe there's a bug somewhere. I'm getting an
From the call to
And yet I still get the error. Edit: Here's the bug: #148 (review). |
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.
General feedback.
Also, it would be simple to add a (implemented by default) |
Performance wise, I'm seeing about a ~5% speedup as a result of making use of this. Not as wild as using |
I agree that having to implement In any case |
Still not particularly happy with this but it's going somewhere. The APIs of I now also have a weird impl |
Yeah, it's absolutely not terrible. But, are you opposed to |
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.
Some more general commentary. This looks awesome.
minijinja/src/value/argtypes.rs
Outdated
/// Similarly it's not possible to borrow dynamic slices | ||
/// ([`SeqObject`](crate::value::SeqObject)) into `&[Value]`. | ||
/// |
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.
Since as_slice()
is gone, what is this referring to?
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.
The underlying ArgTypes
cannot be implemented still. See the remaining internal uses of as_slice
. I'm unsure how this can be resolved due to limitations with how lifetimes are entangled with value. Basically you cannot have a filter taking foo(items: &[Value])
or foo(items: Vec<i32>)
when the items
value was a dynamic sequence.
} | ||
|
||
/// If the value is a struct, return it as [`StructObject`]. | ||
pub fn as_struct(&self) -> Option<&dyn StructObject> { |
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.
Should this also return Some()
when we have a ValueRepr::Map
? That would make its functionality similar to as_seq()
. And if so, maybe StructObject
should be called MapObject
.
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.
At a later point I might introduce a MapObject
which takes arbitrary keys. However that opens up some uncomfortable questions about how to represent keys which I don't want to go into yet.
I ended up adding |
9bc264f
to
f819d28
Compare
f819d28
to
0e56a72
Compare
This changes the object interface to support both structs and sequences with the possibility to add extra behavior (eg: arbitrary key maps) at a future point. There are some challenges with this design however.
Issues:
These are probably something I need to accept:
impl<'a, T: ArgType<'a, Output = T>> ArgType<'a> for Vec<T>
cannot be implemented to support these new dynamic sequences because the lifetime constraints cannot be enabled. Restrict?Things to resolve:
This is stuff that can be fixed:
x[:5]
first converts the entire value before slicing down.Value::as_slice
API cannot return borrowed values for dynamic slices. Internally aas_cow_slice
has been added. Potential solution is to retireas_slice
entirely forSeqObject
.SeqObject::iter
Refs #147