Attribute for defining examples (#23)

This commit is contained in:
Graham Esau 2020-05-17 16:41:19 +01:00
parent 19b9bef395
commit e259955809
4 changed files with 88 additions and 3 deletions

View file

@ -16,7 +16,7 @@ pub struct Attrs {
pub title: Option<String>,
pub description: Option<String>,
pub deprecated: bool,
// TODO pub example: Option<syn::Path>,
pub examples: Vec<syn::Path>,
}
#[derive(Debug)]
@ -111,6 +111,12 @@ impl Attrs {
}
}
Meta(NameValue(m)) if m.path.is_ident("example") => {
if let Ok(fun) = parse_lit_into_path(errors, attr_type, "example", &m.lit) {
self.examples.push(fun)
}
}
Meta(_meta_item) => {
// TODO uncomment this for 0.8.0 (breaking change)
// https://github.com/GREsau/schemars/issues/18