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
- Host: GitHub
- URL: https://github.com/daboross/auto-from
- Owner: daboross
- License: mit
- Created: 2019-02-14T00:37:42.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-14T00:38:15.000Z (over 7 years ago)
- Last Synced: 2025-06-24T23:36:44.583Z (about 1 year ago)
- Language: Rust
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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() }
}
}
```