You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
626: Use one trait for all cases; use constant case for structures r=burrbull a=luojia65
This pull request is the first part of #612. It merges all `ToSanitizedXxxCase` traits in one `ToSanitizedCase` trait. It also replace all use of upper cases into constant cases, in case the source file did not provide underline between words. It rename variables related to cases, for example `name_sc` to `name_snake_case` to be explict.
The changed code merges original case conversation traits into one trait:
```rust
/// Convert self string into specific case without overlapping to svd2rust internal names
pub trait ToSanitizedCase {
/// Convert self into PascalCase.
///
/// Use on name of enumeration values.
fn to_sanitized_pascal_case(&self) -> Cow<str>;
/// Convert self into CONSTANT_CASE.
///
/// Use on name of reader structs, writer structs and enumerations.
fn to_sanitized_constant_case(&self) -> Cow<str>;
/// Convert self into snake_case, must use only if the target is used with extra prefix or suffix.
fn to_sanitized_not_keyword_snake_case(&self) -> Cow<str>;
/// Convert self into snake_case target and ensure target is not a Rust keyword.
///
/// If the sanitized target is a Rust keyword, this function adds an underline `_`
/// to it.
///
/// Use on name of peripheral modules, register modules and field modules.
fn to_sanitized_snake_case(&self) -> Cow<str> {
let s = self.to_sanitized_not_keyword_snake_case();
sanitize_keyword(s)
}
}
```
Note on replacing upper case to constant case: if the source svd file provide enumeration name `InterruptEnable`, it converts to constant case `INTERRUPT_ENABLE` instead of less readable `INTERRUPTENABLE` in current code.
Co-authored-by: luojia65 <[email protected]>
0 commit comments