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

https://github.com/daboross/auto-from

Example usage of rust's attribute-like proc-macros
https://github.com/daboross/auto-from

Last synced: 9 months ago
JSON representation

Example usage of rust's attribute-like proc-macros

Awesome Lists containing this project

README

          

auto-from
=========

Example usage of attribute proc macros. Mostly for my own reference and testing to reproduce issues
in more complicated proc macros.

Transforms this:

```rust
extern crate auto_from;

use auto_from::auto_from;

pub enum Example {
Int(i32),
Vec { length: usize },
}

#[auto_from]
impl Example {
fn ints(i: i32) -> Example {
Example::Int(i)
}

fn any_vec(v: Vec) -> Example
where
T: Clone,
{
Example::Vec { length: v.len() }
}
}
```

into this:

```rust
pub enum Example {
Int(i32),
Vec { length: usize },
}
impl ::std::convert::From for Example {
fn from(i: i32) -> Example {
Example::Int(i)
}
}
impl ::std::convert::From> for Example
where
T: Clone,
{
fn from(v: Vec) -> Example {
Example::Vec { length: v.len() }
}
}
```