convert_string

Crates.ioconvert_string
lib.rsconvert_string
version0.2.0
sourcesrc
created_at2023-08-29 21:17:06.190457
updated_at2024-08-30 19:39:13.973632
descriptionA trait to convert Strings to safe non-keywords and/or convert a Strings case (snake_case, PascalCase, ...).
homepage
repositoryhttps://github.com/Thomblin/convert_string
max_upload_size
id958473
size24,488
Sebastian Detert (Thomblin)

documentation

README

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.2.0"

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

[dependencies]
convert_string = { version = "0.2.0" }

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

Commit count: 12

cargo fmt