Trait ConvertString

Source
pub trait ConvertString {
    // Required methods
    fn is_keyword(&self) -> bool;
    fn to_pascal_case(&self) -> String;
    fn to_snake_case(&self) -> String;
    fn to_valid_key(&self, prefix: &str) -> String;
    fn remove_namespace(&self) -> String;
}

Required Methods§

Source

fn is_keyword(&self) -> bool

return true if the String is a reserved keyword

Example

use convert_string:: ConvertString;
      
assert_eq!(false, String::from("name").is_keyword());
assert_eq!(true, String::from("type").is_keyword());
Source

fn to_pascal_case(&self) -> String

transform String to PascalCase

Example

use convert_string:: ConvertString;
      
assert_eq!("Name", String::from("name").to_pascal_case());
assert_eq!("WithSpaces", String::from("with spaces").to_pascal_case());
assert_eq!("YdTax", String::from("yd_tax").to_pascal_case());
assert_eq!("EdgeCase", String::from("edge-case").to_pascal_case());
assert_eq!("YdTax", String::from("YdTax").to_pascal_case());
assert_eq!("VendorRateId", String::from("VendorRateID").to_pascal_case());
assert_eq!("MvciModuleDescription", String::from("MVCI_MODULE_DESCRIPTION").to_pascal_case());
assert_eq!("HttpresponseCode", String::from("HTTPResponseCode").to_pascal_case());
assert_eq!("Pintype", String::from("PINTYPE").to_pascal_case());
assert_eq!("КоммерческаяИнформация", String::from("КоммерческаяИнформация").to_pascal_case());
assert_eq!("Коммерческаяинформация", String::from("КОММЕРЧЕСКАЯИНФОРМАЦИЯ").to_pascal_case());
assert_eq!("Коммерческаяинформация", String::from("коммерческаяинформация").to_pascal_case());
Source

fn to_snake_case(&self) -> String

transform String to snake_case

Example

use convert_string:: ConvertString;
      
assert_eq!("name", String::from("name").to_snake_case());
assert_eq!("with_spaces", String::from("with spaces").to_snake_case());
assert_eq!("yd_tax", String::from("yd_tax").to_snake_case());
assert_eq!("edge_case", String::from("edge-case").to_snake_case());
assert_eq!("yd_tax", String::from("YdTax").to_snake_case());
assert_eq!("vendor_rate_id", String::from("VendorRateID").to_snake_case());
assert_eq!("_id_context", String::from("_ID_Context").to_snake_case());
assert_eq!("mvci_module_description", String::from("MVCI_MODULE_DESCRIPTION").to_snake_case());
assert_eq!("pintype", String::from("PINTYPE").to_snake_case());
assert_eq!("коммерческая_информация", String::from("КоммерческаяИнформация").to_snake_case());
Source

fn to_valid_key(&self, prefix: &str) -> String

convert the String, if it is a reserved keyword. In that case add the prefix and an underscore

Example

use convert_string:: ConvertString;

assert_eq!("not_a_keyword", String::from("not_a_keyword").to_valid_key(&String::from("r")));  
assert_eq!("no_keyword", String::from("NoKeyword").to_valid_key(&String::from("r")));      
assert_eq!("r_type", String::from("type").to_valid_key(&String::from("r")));    
assert_eq!("r_type", String::from("Type").to_valid_key(&String::from("r")));
assert_eq!("r_abstract", String::from("abstract").to_valid_key(&String::from("r")));
Source

fn remove_namespace(&self) -> String

given an XML like namespace string (ns:name), return the part after the colon

Example

use convert_string:: ConvertString;

assert_eq!("name", String::from("name").remove_namespace());
assert_eq!("name", String::from("ns:name").remove_namespace());

Implementations on Foreign Types§

Source§

impl ConvertString for String

Source§

fn is_keyword(&self) -> bool

return true if the String is a reserved keyword

Source§

fn to_pascal_case(&self) -> String

transform String to PascalCase

Source§

fn to_snake_case(&self) -> String

transform String to snake_case

Source§

fn to_valid_key(&self, prefix: &str) -> String

convert the String, if it is a reserved keyword. In that case add the prefix and an underscore

Source§

fn remove_namespace(&self) -> String

given an XML like namespace string (ns:name), return the part after the colon

Implementors§