Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kanarus/litenum


https://github.com/kanarus/litenum

Last synced: 19 days ago
JSON representation

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),
);
}
```