Skip to main content

pascal_case_from_table

Function pascal_case_from_table 

Source
pub fn pascal_case_from_table(input: &str) -> String
Expand description

Convert a SQL table name (typically snake_case) into PascalCase for use as a Rust struct name.

Splits on _, , and -. Non-alphanumeric characters that are not separators are skipped. The first character of each segment is uppercased; the rest are lowercased — this normalises table names that may have been created in ALLCAPS or mixed case.

Used by umbral-core/inspect.rs (the inspectdb command) to generate struct names from introspected table names.

§Examples

use umbral_casing::pascal_case_from_table;

assert_eq!(pascal_case_from_table("blog_post"),        "BlogPost");
assert_eq!(pascal_case_from_table("auth_user_groups"), "AuthUserGroups");
assert_eq!(pascal_case_from_table("post"),             "Post");
assert_eq!(pascal_case_from_table("tag"),              "Tag");
assert_eq!(pascal_case_from_table("BLOG_POST"),        "BlogPost");
assert_eq!(pascal_case_from_table("blog-post"),        "BlogPost");