Update READMEs

rename
pantonshire 3 years ago
parent 830d5807a0
commit c47706bc5f

@ -11,7 +11,7 @@ Add to your Cargo.toml file:
```toml
[dependencies]
enumscribe = "0.1"
enumscribe = "0.2"
```
Derive macros and [`serde`](https://crates.io/crates/serde) support are enabled by default. They can be disabled by

@ -11,7 +11,7 @@ Add to your Cargo.toml file:
```toml
[dependencies]
enumscribe = "0.1"
enumscribe = "0.2"
```
Derive macros and [`serde`](https://crates.io/crates/serde) support are enabled by default. They can be disabled by
@ -66,6 +66,24 @@ enum Website {
assert_eq!(Website::try_unscribe("GiThUb.CoM"), Some(Website::Github));
```
The same attribute can be used on the enum itself to make all variants case-insensitive. Individual fields may opt back
in to case sensitivity with `#[enumscribe(case_sensitive)]`.
```rust
use enumscribe::TryUnscribe;
#[derive(TryUnscribe, PartialEq, Eq, Debug)]
#[case_insensitive]
enum Website {
#[enumscribe(str = "github.com")]
Github,
#[enumscribe(str = "crates.io")]
CratesDotIo,
}
assert_eq!(Website::try_unscribe("CrAtEs.Io"), Some(Website::CratesDotIo));
```
### "other" variant
You can also have a variant which stores strings that could not be matched to any other variant. This is done using the
`#[enumscribe(other)]` attribute. The variant should have a single field, which is a `String`.

@ -11,7 +11,7 @@ Add to your Cargo.toml file:
```toml
[dependencies]
enumscribe = "0.1"
enumscribe = "0.2"
```
Derive macros and [`serde`](https://crates.io/crates/serde) support are enabled by default. They can be disabled by
@ -66,6 +66,24 @@ enum Website {
assert_eq!(Website::try_unscribe("GiThUb.CoM"), Some(Website::Github));
```
The same attribute can be used on the enum itself to make all variants case-insensitive. Individual fields may opt back
in to case sensitivity with `#[enumscribe(case_sensitive)]`.
```rust
use enumscribe::TryUnscribe;
#[derive(TryUnscribe, PartialEq, Eq, Debug)]
#[case_insensitive]
enum Website {
#[enumscribe(str = "github.com")]
Github,
#[enumscribe(str = "crates.io")]
CratesDotIo,
}
assert_eq!(Website::try_unscribe("CrAtEs.Io"), Some(Website::CratesDotIo));
```
### "other" variant
You can also have a variant which stores strings that could not be matched to any other variant. This is done using the
`#[enumscribe(other)]` attribute. The variant should have a single field, which is a `String`.

Loading…
Cancel
Save