Skip to content

Commit

Permalink
arrow2-convert migration 4: support serde-based types in codegen (#…
Browse files Browse the repository at this point in the history
…3902)

This introduces the `rust.attr.serde_type` attribute, allowing you to
use any `serde`-compatible Rust types in our IDL.
```
table ViewportLayout (
  "attr.rust.derive": "PartialEq",
  "attr.rust.override_crate": "re_viewport"
) {
  space_view_keys: [ubyte] (order: 100, "attr.rust.serde_type": "std::collections::BTreeSet<re_viewer_context::SpaceViewId>");

  tree: [ubyte] (order: 101, "attr.rust.serde_type": "egui_tiles::Tree<re_viewer_context::SpaceViewId>");

  auto_layout: bool (order: 102);
}
```

This unblocks further blueprint experimentations, and is the last
blocker to sunset `arrow2-convert`.

- `SpaceViewComponent`, `SpaceViewMaximized` & `ViewportLayout` are now
all implemented that way.
- `re_viewport` is now free of `arrow2-convert`.

---

`arrow2-convert` migration PR series:
- #3853 
- #3855
- #3897
- #3902
- #3917
  • Loading branch information
teh-cmc authored Oct 19, 2023
1 parent f3a5ae2 commit e537874
Show file tree
Hide file tree
Showing 161 changed files with 4,855 additions and 2,689 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/re_types/definitions/rerun/blueprint.fbs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
include "./blueprint/auto_space_views.fbs";
include "./blueprint/panel_view.fbs";
include "./blueprint/space_view_component.fbs";
include "./blueprint/space_view_maximized.fbs";
include "./blueprint/viewport_layout.fbs";
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
include "arrow/attributes.fbs";
include "python/attributes.fbs";
include "rust/attributes.fbs";

include "rerun/datatypes.fbs";
include "rerun/attributes.fbs";

namespace rerun.blueprint;

// ---

/// A view of a space.
///
/// Unstable. Used for the ongoing blueprint experimentations.
table SpaceViewComponent (
"attr.rust.derive_only": "Clone",
"attr.rust.override_crate": "re_viewport"
) {
space_view: [ubyte] (order: 100, "attr.rust.serde_type": "crate::SpaceViewBlueprint");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
include "arrow/attributes.fbs";
include "python/attributes.fbs";
include "rust/attributes.fbs";

include "rerun/datatypes.fbs";
include "rerun/attributes.fbs";

namespace rerun.blueprint;

// ---

/// Whether a space view is maximized.
///
/// Unstable. Used for the ongoing blueprint experimentations.
table SpaceViewMaximized (
"attr.arrow.transparent",
"attr.rust.derive": "Copy, Default, PartialEq, Eq",
"attr.rust.override_crate": "re_viewport",
"attr.rust.repr": "transparent",
"attr.rust.tuple_struct"
) {
id: [ubyte] (order: 100, nullable, "attr.rust.serde_type": "re_viewer_context::SpaceViewId");
}

27 changes: 27 additions & 0 deletions crates/re_types/definitions/rerun/blueprint/viewport_layout.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
include "arrow/attributes.fbs";
include "python/attributes.fbs";
include "rust/attributes.fbs";

include "rerun/datatypes.fbs";
include "rerun/attributes.fbs";

namespace rerun.blueprint;

// ---

/// A view of a space.
///
/// Unstable. Used for the ongoing blueprint experimentations.
table ViewportLayout (
"attr.rust.derive": "PartialEq",
"attr.rust.override_crate": "re_viewport"
) {
/// space_view_keys
space_view_keys: [ubyte] (order: 100, "attr.rust.serde_type": "std::collections::BTreeSet<re_viewer_context::SpaceViewId>");

/// tree
tree: [ubyte] (order: 101, "attr.rust.serde_type": "egui_tiles::Tree<re_viewer_context::SpaceViewId>");

/// auto_layout
auto_layout: bool (order: 102);
}
8 changes: 8 additions & 0 deletions crates/re_types/definitions/rust/attributes.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ attribute "attr.rust.new_pub_crate";
/// an object of kind `Blueprint` with `attr.rust.override_crate=re_viewport`, the final
/// object will be generated in `crates/re_viewport/src/blueprint`.
attribute "attr.rust.override_crate";

/// Specify on an object field of type `[ubyte]` in order to (de)serialize using a pre-existing
/// `serde` implementation.
///
/// Everything else works the same, include how module names are derived: e.g. if you define
/// an object of kind `Blueprint` with `attr.rust.override_crate=re_viewport`, the final
/// object will be generated in `crates/re_viewport/src/blueprint`.
attribute "attr.rust.serde_type";
35 changes: 20 additions & 15 deletions crates/re_types/src/archetypes/annotation_context.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e537874

Please sign in to comment.