Skip to content

Commit

Permalink
Pass through strings using arrow::buffer under the hood
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed Aug 7, 2023
1 parent ba0704b commit 2547eff
Show file tree
Hide file tree
Showing 30 changed files with 328 additions and 225 deletions.
2 changes: 1 addition & 1 deletion crates/re_data_ui/src/annotation_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fn class_description_ui(ui: &mut egui::Ui, class: &ClassDescription, id: ClassId
.and_then(|info| info.label.as_ref())
.map_or_else(
|| format!("id {id:?}"),
|label| label.0.clone(),
|label| label.0.as_str().to_owned(),
),
);
});
Expand Down
2 changes: 1 addition & 1 deletion crates/re_space_view_spatial/src/parts/arrows3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Arrows3DPart {
.filter_map(
move |(annotation_info, vector, origin, label, color, labeled_instance)| {
let origin = origin.unwrap_or_default();
let label = annotation_info.label(label.map(|l| l.0).as_ref());
let label = annotation_info.label(label.as_ref().map(|l| l.as_str()));
match (vector, label) {
(vector, Some(label)) => {
let midpoint =
Expand Down
2 changes: 1 addition & 1 deletion crates/re_space_view_spatial/src/parts/boxes2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Boxes2DPart {
let color =
annotation_info.color(color.map(move |c| c.to_array()).as_ref(), default_color);
let radius = radius.map_or(Size::AUTO, |r| Size::new_scene(r.0));
let label = annotation_info.label(label.map(|l| l.0).as_ref());
let label = annotation_info.label(label.as_ref().map(|l| l.as_str()));

self.0.extend_bounding_box(
macaw::BoundingBox {
Expand Down
2 changes: 1 addition & 1 deletion crates/re_space_view_spatial/src/parts/boxes3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Boxes3DPart {
box_lines.outline_mask_ids(*outline_mask_ids);
}

if let Some(label) = annotation_info.label(label.as_ref().map(|s| &s.0)) {
if let Some(label) = annotation_info.label(label.as_ref().map(|s| s.as_str())) {
self.0.ui_labels.push(UiLabel {
text: label,
target: UiLabelTarget::Position3D(
Expand Down
2 changes: 1 addition & 1 deletion crates/re_space_view_spatial/src/parts/points2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Points2DPart {
)
.filter_map(
move |(annotation_info, point, label, color, labeled_instance)| {
let label = annotation_info.label(label.map(|l| l.0).as_ref());
let label = annotation_info.label(label.as_ref().map(|l| l.as_str()));
match (point, label) {
(point, Some(label)) => Some(UiLabel {
text: label,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_space_view_spatial/src/parts/points3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Points3DPart {
)
.filter_map(
move |(annotation_info, point, label, color, labeled_instance)| {
let label = annotation_info.label(label.map(|l| l.0).as_ref());
let label = annotation_info.label(label.as_ref().map(|l| l.as_str()));
match (point, label) {
(point, Some(label)) => Some(UiLabel {
text: label,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_space_view_time_series/src/view_part_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl TimeSeriesSystem {
// TODO(andreas): Support entity path
let color = annotation_info
.color(color.map(|c| c.to_array()).as_ref(), default_color);
let label = annotation_info.label(label.map(|l| l.into()).as_ref());
let label = annotation_info.label(label.as_ref().map(|l| l.as_str()));

const DEFAULT_RADIUS: f32 = 0.75;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace rerun.archetypes;
/// \rs \include:../../../../../docs/code-examples/transform3d_simple_v2.rs
/// \rs ```
table TextEntry (
"attr.rust.derive": "PartialEq",
"attr.rust.derive": "PartialEq, Eq",
order: 100
) {
bodies: [rerun.components.Body] ("attr.rerun.component_required", required, order: 1000);
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/source_hash.txt

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

2 changes: 1 addition & 1 deletion crates/re_types/src/archetypes/text_entry.rs

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

45 changes: 45 additions & 0 deletions crates/re_types/src/arrow_adapter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use arrow2::buffer::Buffer;

#[derive(Clone, Debug, Default)]
pub struct ArrowString(pub Buffer<u8>);

impl PartialEq for ArrowString {
fn eq(&self, other: &Self) -> bool {
self.as_str() == other.as_str()
}
}

impl Eq for ArrowString {}

impl PartialOrd for ArrowString {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.as_str().partial_cmp(other.as_str())
}
}

impl Ord for ArrowString {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.as_str().cmp(other.as_str())
}
}

impl ArrowString {
#[inline]
pub fn as_str(&self) -> &str {
std::str::from_utf8(self.0.as_ref()).unwrap()
}
}

impl From<String> for ArrowString {
#[inline]
fn from(value: String) -> Self {
Self(value.as_bytes().to_vec().into())
}
}

impl From<&str> for ArrowString {
#[inline]
fn from(value: &str) -> Self {
Self(value.as_bytes().to_vec().into())
}
}
41 changes: 22 additions & 19 deletions crates/re_types/src/components/body.rs

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

4 changes: 2 additions & 2 deletions crates/re_types/src/components/body_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ impl Body {
impl From<String> for Body {
#[inline]
fn from(value: String) -> Self {
Self(value)
Self(value.into())
}
}

impl From<&str> for Body {
#[inline]
fn from(value: &str) -> Self {
Self(value.to_owned())
Self(value.into())
}
}
41 changes: 22 additions & 19 deletions crates/re_types/src/components/label.rs

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

6 changes: 3 additions & 3 deletions crates/re_types/src/components/label_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ impl Label {
impl From<String> for Label {
#[inline]
fn from(value: String) -> Self {
Self(value)
Self(value.into())
}
}

impl From<&str> for Label {
#[inline]
fn from(value: &str) -> Self {
Self(value.to_owned())
Self(value.into())
}
}

impl From<Label> for String {
#[inline]
fn from(value: Label) -> Self {
value.0
value.as_str().to_owned()
}
}

Expand Down
41 changes: 22 additions & 19 deletions crates/re_types/src/components/level.rs

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

4 changes: 2 additions & 2 deletions crates/re_types/src/components/level_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ impl Level {
impl From<String> for Level {
#[inline]
fn from(value: String) -> Self {
Self(value)
Self(value.into())
}
}

impl From<&str> for Level {
#[inline]
fn from(value: &str) -> Self {
Self(value.to_owned())
Self(value.into())
}
}
Loading

0 comments on commit 2547eff

Please sign in to comment.