This crate provides derive macros for converting between simple enums and strings. It also includes derive macros for [`serde::Serialize`](https://docs.serde.rs/serde/trait.Serialize.html) and [`serde::Deserialize`](https://docs.serde.rs/serde/trait.Deserialize.html) for simple enums.
This crate provides derive macros for converting between simple enums and strings. It also includes derive macros for
[`serde::Serialize`](https://docs.serde.rs/serde/trait.Serialize.html) and
[`serde::Deserialize`](https://docs.serde.rs/serde/trait.Deserialize.html) for simple enums.
## Adding enumscribe to your project
Add to your Cargo.toml file:
```toml
[dependencies]
enumscribe = "0.1"
```
Derive macros and [`serde`](https://crates.io/crates/serde) support are enabled by default. They can be disabled by
setting `default-features = false`.
It is also possible to use the `enumscribe_derive` crate on its own without using the `enumscribe` crate. However,
doing so means that you will only be able to derive `serde::Serialize` and `serde::Deserialize`.
## Usage
There are a variety of different traits that you can derive. The "Scribe" traits are for converting from an enum to a string, and the "Unscribe" traits are for
converting a string to an enum.
There are a variety of different traits that you can derive. The "Scribe" traits are for converting from an enum to a
string, and the "Unscribe" traits are for converting a string to an enum.
The `#[enumscribe(str = "...")]` allows us to specify what string should be used to represent a particular variant. If this is omitted, the name of the variant
will be used instead.
The `#[enumscribe(str = "...")]` allows us to specify what string should be used to represent a particular variant. If
this is omitted, the name of the variant will be used instead.
### Case insensitivity
The `#[enumscribe(case_insensitive)]` attribute can be used to make the "Unscribe" traits perform case-insensitive matching for a variant:
The `#[enumscribe(case_insensitive)]` attribute can be used to make the "Unscribe" traits perform case-insensitive
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`.
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`.
This crate provides derive macros for converting between simple enums and strings. It also includes derive macros for [`serde::Serialize`](https://docs.serde.rs/serde/trait.Serialize.html) and [`serde::Deserialize`](https://docs.serde.rs/serde/trait.Deserialize.html) for simple enums.
This crate provides derive macros for converting between simple enums and strings. It also includes derive macros for
[`serde::Serialize`](https://docs.serde.rs/serde/trait.Serialize.html) and
[`serde::Deserialize`](https://docs.serde.rs/serde/trait.Deserialize.html) for simple enums.
## Adding enumscribe to your project
Add to your Cargo.toml file:
```toml
[dependencies]
enumscribe = "0.1"
```
Derive macros and [`serde`](https://crates.io/crates/serde) support are enabled by default. They can be disabled by
setting `default-features = false`.
It is also possible to use the `enumscribe_derive` crate on its own without using the `enumscribe` crate. However,
doing so means that you will only be able to derive `serde::Serialize` and `serde::Deserialize`.
## Usage
There are a variety of different traits that you can derive. The "Scribe" traits are for converting from an enum to a string, and the "Unscribe" traits are for
converting a string to an enum.
There are a variety of different traits that you can derive. The "Scribe" traits are for converting from an enum to a
string, and the "Unscribe" traits are for converting a string to an enum.
The `#[enumscribe(str = "...")]` allows us to specify what string should be used to represent a particular variant. If this is omitted, the name of the variant
will be used instead.
The `#[enumscribe(str = "...")]` allows us to specify what string should be used to represent a particular variant. If
this is omitted, the name of the variant will be used instead.
### Case insensitivity
The `#[enumscribe(case_insensitive)]` attribute can be used to make the "Unscribe" traits perform case-insensitive matching for a variant:
The `#[enumscribe(case_insensitive)]` attribute can be used to make the "Unscribe" traits perform case-insensitive
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`.
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`.
This crate provides derive macros for converting between simple enums and strings. It also includes derive macros for [`serde::Serialize`](https://docs.serde.rs/serde/trait.Serialize.html) and [`serde::Deserialize`](https://docs.serde.rs/serde/trait.Deserialize.html) for simple enums.
This crate provides derive macros for converting between simple enums and strings. It also includes derive macros for
[`serde::Serialize`](https://docs.serde.rs/serde/trait.Serialize.html) and
[`serde::Deserialize`](https://docs.serde.rs/serde/trait.Deserialize.html) for simple enums.
## Adding enumscribe to your project
Add to your Cargo.toml file:
```toml
[dependencies]
enumscribe = "0.1"
```
Derive macros and [`serde`](https://crates.io/crates/serde) support are enabled by default. They can be disabled by
setting `default-features = false`.
It is also possible to use the `enumscribe_derive` crate on its own without using the `enumscribe` crate. However,
doing so means that you will only be able to derive `serde::Serialize` and `serde::Deserialize`.
## Usage
There are a variety of different traits that you can derive. The "Scribe" traits are for converting from an enum to a string, and the "Unscribe" traits are for
converting a string to an enum.
There are a variety of different traits that you can derive. The "Scribe" traits are for converting from an enum to a
string, and the "Unscribe" traits are for converting a string to an enum.
The `#[enumscribe(str = "...")]` allows us to specify what string should be used to represent a particular variant. If this is omitted, the name of the variant
will be used instead.
The `#[enumscribe(str = "...")]` allows us to specify what string should be used to represent a particular variant. If
this is omitted, the name of the variant will be used instead.
### Case insensitivity
The `#[enumscribe(case_insensitive)]` attribute can be used to make the "Unscribe" traits perform case-insensitive matching for a variant:
The `#[enumscribe(case_insensitive)]` attribute can be used to make the "Unscribe" traits perform case-insensitive
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`.
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`.
/// Derives `enumscribe::ScribeStaticStr` for an enum. This allows the enum to be converted to
/// Derives [`enumscribe::ScribeStaticStr`](https://docs.rs/enumscribe/latest/enumscribe/trait.ScribeStaticStr.html) for an enum. This allows the enum to be converted to
/// a `&'static str` using the `scribe()` method.
///
/// You may annotate variants with `#[enumscribe(str = "foo")]` to specify what string the variant
/// Derives `enumscribe::TryScribeStaticStr` for an enum. This allows the enum to be converted to
/// Derives [`enumscribe::TryScribeStaticStr`](https://docs.rs/enumscribe/latest/enumscribe/trait.TryScribeStaticStr.html) for an enum. This allows the enum to be converted to
/// a `Option<&'static str>` using the `try_scribe()` method.
///
/// You may annotate variants with `#[enumscribe(str = "foo")]` to specify what string the variant
/// Derives `enumscribe::ScribeString` for an enum. This allows the enum to be converted to
/// Derives [`enumscribe::ScribeString`](https://docs.rs/enumscribe/latest/enumscribe/trait.ScribeString.html) for an enum. This allows the enum to be converted to
/// a `String` using the `scribe()` method.
///
/// This behaves almost identically to [`ScribeCowStr`](derive.ScribeCowStr.html), except the
/// Derives `enumscribe::TryScribeString` for an enum. This allows the enum to be converted to
/// Derives [`enumscribe::TryScribeString`](https://docs.rs/enumscribe/latest/enumscribe/trait.TryScribeString.html) for an enum. This allows the enum to be converted to
/// a `Option<String>` using the `try_scribe()` method.
///
/// This behaves almost identically to [`TryScribeCowStr`](derive.TryScribeCowStr.html), except the
/// Derives `enumscribe::ScribeCowStr` for an enum. This allows the enum to be converted to
/// Derives [`enumscribe::ScribeCowStr`](https://docs.rs/enumscribe/latest/enumscribe/trait.ScribeCowStr.html) for an enum. This allows the enum to be converted to
/// a `Cow<'static, str>` using the `scribe()` method.
///
/// You may annotate variants with `#[enumscribe(str = "foo")]` to specify what string the variant
/// Derives `enumscribe::TryScribeCowStr` for an enum. This allows the enum to be converted to
/// Derives [`enumscribe::TryScribeCowStr`](https://docs.rs/enumscribe/latest/enumscribe/trait.TryScribeCowStr.html) for an enum. This allows the enum to be converted to
/// a `Option<Cow<'static, str>>` using the `try_scribe()` method.
///
/// You may annotate variants with `#[enumscribe(str = "foo")]` to specify what string the variant
/// Derives `enumscribe::Unscribe` for an enum. This allows a `&str` to be converted to the
/// Derives [`enumscribe::Unscribe`](https://docs.rs/enumscribe/latest/enumscribe/trait.Unscribe.html) for an enum. This allows a `&str` to be converted to the
/// enum using the `unscribe()` associated function.
///
/// You may annotate variants with `#[enumscribe(str = "foo")]` to specify what string should
/// Derives `enumscribe::TryUnscribe` for an enum. This allows a `&str` to be converted to an
/// Derives [`enumscribe::TryUnscribe`](https://docs.rs/enumscribe/latest/enumscribe/trait.TryUnscribe.html) for an enum. This allows a `&str` to be converted to an
/// `Option` of the enum using the `try_unscribe()` associated function.
///
/// You may annotate variants with `#[enumscribe(str = "foo")]` to specify what string should