Crates.io | snake_case |
lib.rs | snake_case |
version | 0.3.1 |
source | src |
created_at | 2019-09-24 14:01:20.835533 |
updated_at | 2021-03-13 09:08:03.486503 |
description | SnakeCase is a String-like type that can only contain valid non-empty snake_case |
homepage | https://github.com/emilk/snake_case |
repository | https://github.com/emilk/snake_case |
max_upload_size | |
id | 167289 |
size | 10,871 |
snake_case
snake_case
identifiersThe purpose of this crate is to expose the type SnakeCase
, a wrapper around a String
that can only contain valid, non-empty snake_case without leading digits. In other words, it always matches ^[_a-z][_a-z0-9]*$
NOTE: ___foo__bar_
is considered valid snake case by this crate.
TL;DR: SnakeCase
can hold any string that is also a valid lower case identifier in Rust.
The common case for this is unique identifiers, for which snake case is perfectly suited. SnakeCase
will always be valid, meaning you will never have the problem of trailing spaces or empty strings.
let id = SnakeCase::try_from_str("hello_world").unwrap();
assert_eq!(id, "hello_world");
There is also SnakeCaseRef
which is a non-owning reference to a snake_case string.
If you enable the "serde"
feature then SnakeCase
will implement Serialize
and Deserialize
.
Deserialize
will fail if a string is not valid snake case.