21 lines
564 B
Rust
21 lines
564 B
Rust
extern crate proc_macro;
|
|
use proc_macro::TokenStream;
|
|
use quote::quote;
|
|
use syn::{parse_macro_input, DeriveInput};
|
|
|
|
#[proc_macro_derive(IRI)]
|
|
pub fn derive_iri(input: TokenStream) -> TokenStream {
|
|
let DeriveInput { ident, .. } = parse_macro_input!(input);
|
|
quote! {
|
|
impl std::str::FromStr for #ident {
|
|
type Err = ();
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
let mut ident = #ident::default();
|
|
ident.id = s.into();
|
|
Ok(ident)
|
|
}
|
|
}
|
|
}
|
|
.into()
|
|
}
|