This pull request is the first part of https://github.com/rust-embedded/svd2rust/pull/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:
/// 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.
This pull request is the first part of https://github.com/rust-embedded/svd2rust/pull/612. It merges all
ToSanitizedXxxCase
traits in oneToSanitizedCase
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 examplename_sc
toname_snake_case
to be explict.The changed code merges original case conversation traits into one trait:
Note on replacing upper case to constant case: if the source svd file provide enumeration name
InterruptEnable
, it converts to constant caseINTERRUPT_ENABLE
instead of less readableINTERRUPTENABLE
in current code.