Redesign re_types API ("as_components" model)#3162
Conversation
db96379 to
2f79e8e
Compare
2f79e8e to
462e4a9
Compare
crates/re_types/src/archetype.rs
Outdated
|
|
||
| /// Returns the names of all components that _must_ be provided by the user when constructing | ||
| /// this archetype. | ||
| fn required_components() -> ::std::borrow::Cow<'static, [ComponentName]>; |
There was a problem hiding this comment.
What's with the the extra :: ? Isn't std::borrow::Cow verbose enough?
There was a problem hiding this comment.
Old habits from codegen code; not needed here
crates/re_types/src/archetype.rs
Outdated
| /// Returns the names of all components that must, should and may be provided by the user when | ||
| /// constructing this archetype. | ||
| #[inline] | ||
| fn all_components() -> ::std::borrow::Cow<'static, [ComponentName]> { |
There was a problem hiding this comment.
This is one of several methods that the user really shouldn't override. We should probably note that in the docstring, and maybe put them in their own section
There was a problem hiding this comment.
It does make sense to override this if you have everything available statically and want to avoid allocations.
I'll detail that in the docstring.
crates/re_types/src/archetype.rs
Outdated
| /// Given an iterator of Arrow arrays and their respective field metadata, deserializes them | ||
| /// into this archetype. | ||
| /// | ||
| /// Panics on failure. |
There was a problem hiding this comment.
I'm not sure we should have the panicking from_arrow - it seems like a footgun waiting to happen. One should never assume some arrow data follows the expected schema.
…mponentList traits
568f7a2 to
4d03cf4
Compare
Commit by commit
This PR redesigns
re_types's traits in an effort to allow users to easily implement their own handwritten Archetypes/Components/Datatypes, or even extend builtin ones.It also introduces the of notion of "component lists" as first-class citizens, which is the basis of our archetype extension story.
The new traits are designed in a way to make most of their methods optional, with sane default implementations that either return errors or automatically "do the right thing" by relying on other methods.
In most cases, this makes it possible to implement "just what you need", and everything should work fine.
The new
LoggableList,ComponentList&DatatypeListtraits allow for erased collections of components, and do not require any effort on part of the user as we provide blanket implementations for all common cases.The legacy iterator-based compatibility layer in the deserialization path is gone.
Similarly, all the awful datatype extension hacks are gone. Extensions live in the
Fieldand theFieldalone, until we get rid ofarrow2-convertandDataCell::component_namein the future.Quoting the crate-level doc:
Fixes #3178
Part of #3103
Implementing a custom component is now fairly straightforward:
And so is implementing a custom archetype:
As a nice side-effect of these simplified traits, the custom_space_view example is now much simpler:

What
Checklist