#reserved #string #string-conversion #case #formatting #keyword

convert_string

A trait to convert Strings to safe non-keywords and/or convert a Strings case (snake_case, PascalCase, ...)

4 releases

0.1.3 Nov 25, 2023
0.1.2 Aug 30, 2023
0.1.1 Aug 29, 2023
0.1.0 Aug 29, 2023

#760 in Text processing

Download history 21/week @ 2024-01-08 2/week @ 2024-01-15 55/week @ 2024-01-22 10/week @ 2024-01-29 5/week @ 2024-02-05 21/week @ 2024-02-12 175/week @ 2024-02-19 45/week @ 2024-02-26 56/week @ 2024-03-04 44/week @ 2024-03-11 23/week @ 2024-03-18 16/week @ 2024-03-25 66/week @ 2024-04-01 19/week @ 2024-04-08 17/week @ 2024-04-15 39/week @ 2024-04-22

143 downloads per month
Used in xml_schema_generator

Apache-2.0

13KB
138 lines

convert_string

github crates.io docs.rs build status

A trait for String-like types to check if a string is a reserved keyword, and convert it to a safe non-keyword if so. Offers some type conversions as well

Only strict and reserved keywords are checked against; weak keywords are not include

You can add this dependency with:

[dependencies]
convert_string = "0.1.3"

Example

use convert_string::ConvertString;;

assert_eq!("r_type", String::from("type").to_valid_key(&String::from("r")));
assert_eq!("foo", String::from("ns:foo").remove_namespace());
assert_eq!("YdTax", String::from("yd_tax").to_pascal_case());
assert_eq!("yd_tax", String::from("YdTax").to_snake_case());

Rust Editions

By default, the keywords added in Rust Edition 2018 are included in the list of chec This can be disabled with default-features = false in your Cargo.toml.

[dependencies]
convert_string = { version = "0.1.3", default-features = false }

Future Rust editions may add new keywords, and this crate will be updated to reflect (Or you can create an issue on github if I don't.)

Credit

Huge parts of this library are taken from https://github.com/JoelCourtney/check_keyword

Source

License: Apache-2.0

https://github.com/Thomblin/convert_string

No runtime deps