-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add description of the project in the README.md, with usage example - Add lib.rs documentation
- Loading branch information
Showing
2 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,32 @@ | ||
# enum-stringify | ||
|
||
Future set of macros to generate to string functions for enums, similar to [string_enum](https://crates.io/crates/string-enum) but with a different approach. | ||
Set of macros (only one for now) to generate a string representation of an enum. When using | ||
`#[derive(EnumStringify)]` on an enum, it will implement `std::fmt::Display`, `TryFrom<&str>`, | ||
`TryFrom<String>` and `std::str::FromStr` for it. It will use the name of the enum variant as the | ||
string representation. | ||
|
||
## Usage | ||
|
||
```rust | ||
use enum_stringify::EnumStringify; | ||
|
||
#[derive(EnumStringify)] | ||
enum MyEnum { | ||
Variant1, | ||
Variant2, | ||
Variant3, | ||
} | ||
|
||
fn main() { | ||
println!("{}", MyEnum::Variant1); // Prints "Variant1" | ||
assert_eq!(MyEnum::Variant1.to_string(), "Variant1"); | ||
assert_eq!(MyEnum::try_from("Variant2").unwrap(), MyEnum::Variant2); | ||
assert_eq!(MyEnum::try_from("Variant3".to_string()).unwrap(), MyEnum::Variant3); | ||
assert_eq!(MyEnum::from_str("Variant1").unwrap(), MyEnum::Variant1); | ||
} | ||
``` | ||
|
||
## Documentation and installation | ||
|
||
See [docs.rs](https://docs.rs/enum-stringify) for documentation. | ||
It is available on [crates.io](https://crates.io/crates/enum-stringify) as well. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters