Non blank string type for approach suggested by Alexis King - "Parse, don't validate".
Add dependency:
shell
cargo add non-blank-string-rs
Use:
```rust let username = NonBlankString::from_str("Hellow")?; let username: NonBlankString = "Hellow".parse()?;
// fn login(username: &str) login(&username) ```
Useful for REST API Endpoints, i.e. /api/register
accepts:
```rust
struct UserRegistrationRequest { pub username: NonBlankString, ... } ```
Incoming JSON with blank value in username
field will raise deserialization error (Serde).
Add to Cargo.toml
:
toml
[dev-dependencies]
non-blank-string-rs = { version = "1.0.3", features = ["utils"] }
Functions:
get_random_nonblank_string()
- return random NonBlankString
. Useful for tests.