Skip to content

Commit

Permalink
Move case conversions to new crate re_case
Browse files Browse the repository at this point in the history
Because I want to use it to get a snake_case url from a `ComponentName`
  • Loading branch information
emilk committed Jun 3, 2024
1 parent 4104808 commit 3c8a452
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 15 deletions.
9 changes: 8 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4273,6 +4273,13 @@ dependencies = [
"walkdir",
]

[[package]]
name = "re_case"
version = "0.17.0-alpha.3"
dependencies = [
"convert_case",
]

[[package]]
name = "re_chunk"
version = "0.17.0-alpha.3"
Expand Down Expand Up @@ -5118,7 +5125,6 @@ dependencies = [
"anyhow",
"camino",
"clang-format",
"convert_case",
"flatbuffers",
"indent",
"itertools 0.13.0",
Expand All @@ -5128,6 +5134,7 @@ dependencies = [
"rayon",
"re_arrow2",
"re_build_tools",
"re_case",
"re_error",
"re_log",
"re_tracing",
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ re_analytics = { path = "crates/re_analytics", version = "=0.17.0-alpha.3", defa
re_blueprint_tree = { path = "crates/re_blueprint_tree", version = "=0.17.0-alpha.3", default-features = false }
re_build_info = { path = "crates/re_build_info", version = "=0.17.0-alpha.3", default-features = false }
re_build_tools = { path = "crates/re_build_tools", version = "=0.17.0-alpha.3", default-features = false }
re_case = { path = "crates/re_case", version = "=0.17.0-alpha.3", default-features = false }
re_chunk = { path = "crates/re_chunk", version = "=0.17.0-alpha.3", default-features = false }
re_context_menu = { path = "crates/re_context_menu", version = "=0.17.0-alpha.3", default-features = false }
re_crash_handler = { path = "crates/re_crash_handler", version = "=0.17.0-alpha.3", default-features = false }
Expand Down
27 changes: 27 additions & 0 deletions crates/re_case/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "re_case"
authors.workspace = true
description = "Case conversions, the way Rerun likes them"
edition.workspace = true
homepage.workspace = true
include.workspace = true
license.workspace = true
publish = true
readme = "README.md"
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[lints]
workspace = true

[package.metadata.docs.rs]
all-features = true


[features]
default = []


[dependencies]
convert_case.workspace = true
10 changes: 10 additions & 0 deletions crates/re_case/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# re_case

Part of the [`rerun`](https://github.com/rerun-io/rerun) family of crates.

[![Latest version](https://img.shields.io/crates/v/re_case.svg)](https://crates.io/crates/re_case?speculative-link)
[![Documentation](https://docs.rs/re_case/badge.svg)](https://docs.rs/re_case?speculative-link)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![Apache](https://img.shields.io/badge/license-Apache-blue.svg)

Case conversions, the way Rerun likes them.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ---
//! Case conversions, the way Rerun likes them.
/// Converts a snake or pascal case input into a snake case output.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types_builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ all-features = true

[dependencies]
re_build_tools.workspace = true
re_case.workspace = true
re_error.workspace = true
re_log = { workspace = true, features = ["setup"] }
re_tracing = { workspace = true, features = ["server"] }
Expand All @@ -31,7 +32,6 @@ anyhow.workspace = true
arrow2.workspace = true
camino.workspace = true
clang-format.workspace = true
convert_case.workspace = true
flatbuffers.workspace = true
indent.workspace = true
itertools.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types_builder/src/codegen/cpp/includes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Includes {
}
};

let typname = crate::to_snake_case(typname);
let typname = re_case::to_snake_case(typname);

if is_testing_fqname(&self.fqname) == is_testing_fqname(included_fqname) {
// If the type is in the same library, we use a relative path.
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types_builder/src/codegen/docs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ fn write_archetype_fields(
{
page.push_str(&format!(
"* [{view_name}](../views/{}.md)",
crate::to_snake_case(view_name)
re_case::to_snake_case(view_name)
));
if let Some(explanation) = explanation {
page.push_str(&format!(" ({explanation})"));
Expand Down
8 changes: 4 additions & 4 deletions crates/re_types_builder/src/codegen/rust/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ fn quote_union(
let quoted_custom_clause = quote_meta_clause_from_obj(obj, ATTR_RUST_CUSTOM_CLAUSE, "");

let quoted_fields = fields.iter().map(|obj_field| {
let name = format_ident!("{}", crate::to_pascal_case(&obj_field.name));
let name = format_ident!("{}", re_case::to_pascal_case(&obj_field.name));

let quoted_doc = quote_field_docs(reporter, obj_field);
let quoted_type = quote_field_type_from_object_field(obj_field);
Expand Down Expand Up @@ -625,7 +625,7 @@ fn quote_union(
quote!()
} else {
let quoted_matches = fields.iter().map(|obj_field| {
let name = format_ident!("{}", crate::to_pascal_case(&obj_field.name));
let name = format_ident!("{}", re_case::to_pascal_case(&obj_field.name));

if obj_field.typ == Type::Unit {
quote!(Self::#name => 0)
Expand Down Expand Up @@ -1087,7 +1087,7 @@ fn quote_trait_impls_from_obj(
fqname, name, kind, ..
} = obj;

let display_name = crate::to_human_case(name);
let display_name = re_case::to_human_case(name);
let name = format_ident!("{name}");

match kind {
Expand Down Expand Up @@ -1351,7 +1351,7 @@ fn quote_trait_impls_from_obj(
.is_attr_set(ATTR_RUST_GENERATE_FIELD_INFO)
{
let field_infos = obj.fields.iter().map(|field| {
let display_name = crate::to_human_case(&field.name);
let display_name = re_case::to_human_case(&field.name);
let documentation = field
.docs
.lines_with_tag_matching(|tag| tag.is_empty())
Expand Down
4 changes: 1 addition & 3 deletions crates/re_types_builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
#![allow(clippy::unwrap_used)]

// NOTE: Official generated code from flatbuffers; ignore _everything_.
mod casing;

#[allow(
warnings,
unused,
Expand All @@ -117,8 +117,6 @@ mod casing;
)]
mod reflection;

use casing::{to_human_case, to_pascal_case, to_snake_case};

use std::collections::{BTreeMap, BTreeSet};

use anyhow::Context as _;
Expand Down
6 changes: 3 additions & 3 deletions crates/re_types_builder/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ impl Object {

/// The `snake_case` name of the object, e.g. `translation_and_mat3x3`.
pub fn snake_case_name(&self) -> String {
crate::to_snake_case(&self.name)
re_case::to_snake_case(&self.name)
}

/// Returns true if this object is part of testing and not to be used in the production SDK.
Expand Down Expand Up @@ -807,12 +807,12 @@ impl ObjectField {

/// The `snake_case` name of the field, e.g. `translation_and_mat3x3`.
pub fn snake_case_name(&self) -> String {
crate::to_snake_case(&self.name)
re_case::to_snake_case(&self.name)
}

/// The `PascalCase` name of the field, e.g. `TranslationAndMat3x3`.
pub fn pascal_case_name(&self) -> String {
crate::to_pascal_case(&self.name)
re_case::to_pascal_case(&self.name)
}

/// Returns true if this object is part of testing and not to be used in the production SDK.
Expand Down

0 comments on commit 3c8a452

Please sign in to comment.