Some docs

This commit is contained in:
Richard Dodd
2018-09-29 15:06:23 +01:00
parent 3f0f739e17
commit da65fe5a52
4 changed files with 35 additions and 1 deletions
+6
View File
@@ -6,6 +6,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! Stuff to handle where the case of the source (e.g. `my-field`) is different to the
//! field/variant (e.g. `my_field`).
// See https://users.rust-lang.org/t/psa-dealing-with-warning-unused-import-std-ascii-asciiext-in-today-s-nightly/13726
#[allow(deprecated, unused_imports)]
use std::ascii::AsciiExt;
@@ -14,6 +17,7 @@ use std::str::FromStr;
use self::RenameRule::*;
/// The different possible ways to change case of fields in a struct, or variants in an enum.
#[derive(PartialEq)]
pub enum RenameRule {
/// Don't apply a default rename rule.
@@ -40,6 +44,7 @@ pub enum RenameRule {
}
impl RenameRule {
/// Apply a renaming rule to an enum variant, returning the version expected in the source.
pub fn apply_to_variant(&self, variant: &str) -> String {
match *self {
None | PascalCase => variant.to_owned(),
@@ -64,6 +69,7 @@ impl RenameRule {
}
}
/// Apply a renaming rule to a struct field, returning the version expected in the source.
pub fn apply_to_field(&self, field: &str) -> String {
match *self {
None | LowerCase | SnakeCase => field.to_owned(),