Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kanarus/litenum
https://github.com/kanarus/litenum
Last synced: 19 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kanarus/litenum
- Owner: kanarus
- Created: 2023-08-08T13:45:09.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-16T18:09:14.000Z (3 months ago)
- Last Synced: 2024-10-07T04:19:09.635Z (about 1 month ago)
- Language: Rust
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
litenum
litenum is the *minimal* utility for conversion between **literal** and **enum** !
## Features
- minimal inplementation
- no std, no alloc## How to use
### to literal
```rust
#[litenum::to]
enum AnkerTarget {
_blank,
_self,
_top,
_parent,
}fn main() {
assert_eq!(
AnkerTarget::_blank.lit(),
"_blank",
)
}
```### from literal
```rust
#[litenum::from]
#[derive(Debug, PartialEq)]
enum AnkerTarget {
_blank,
_self,
_top,
_parent,
}fn main() {
assert_eq!(
AnkerTarget::from_lit("_blank"),
Some(AnkerTarget::_blank),
)
}
```### impl both at once
```rust
#[litenum::ium] // same as
// `#[litenum::to] #[litenum::from]`
#[derive(Debug, PartialEq)]
enum AnkerTarget {
_blank,
_self,
_top,
_parent,
}fn main() {
assert_eq!(
AnkerTarget::_blank.lit(),
"_blank",
);assert_eq!(
AnkerTarget::from_lit("_blank"),
Some(AnkerTarget::_blank),
);
}
```