Skip to main content

pascal_case_from_ident

Function pascal_case_from_ident 

Source
pub fn pascal_case_from_ident(name: &str) -> String
Expand description

Convert a kebab/snake-case identifier or user-provided name into PascalCase for use as a Rust type name or plugin struct name.

Splits on - and _. The first character of each segment is uppercased; the remaining characters are passed through unchanged. This preserves digits and already-correct casing in subsequent positions (api2Api2, not Api2 which lowercasing would give).

Used by umbral-cli/scaffold.rs (to produce {Name}Plugin) and umbral-openapi (to produce OpenAPI schema names from model names that are already PascalCase).

§Examples

use umbral_casing::pascal_case_from_ident;

assert_eq!(pascal_case_from_ident("posts"),       "Posts");
assert_eq!(pascal_case_from_ident("blog_engine"), "BlogEngine");
assert_eq!(pascal_case_from_ident("blog-engine"), "BlogEngine");
assert_eq!(pascal_case_from_ident("api2"),        "Api2");
assert_eq!(pascal_case_from_ident("BlogPost"),    "BlogPost");
assert_eq!(pascal_case_from_ident("task_queue"),  "TaskQueue");