api-macro: drop ToTokens for SimpleIdent

The user must be explicit about whether the ident or string
is required.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-12-03 11:58:35 +01:00
parent b7ecf3a597
commit f3f15c2893

View File

@ -3,7 +3,7 @@ use std::collections::HashMap;
use std::convert::TryFrom;
use std::fmt;
use proc_macro2::{Ident, Span, TokenStream};
use proc_macro2::{Ident, Span};
use syn::parse::{Parse, ParseStream};
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
@ -43,10 +43,10 @@ impl SimpleIdent {
Ok(unsafe { self.into_ident_unchecked() })
}
//#[inline]
//pub fn span(&self) -> Span {
// self.0.span()
//}
#[inline]
pub fn span(&self) -> Span {
self.0.span()
}
}
impl Eq for SimpleIdent {}
@ -83,12 +83,6 @@ impl Borrow<str> for SimpleIdent {
}
}
impl quote::ToTokens for SimpleIdent {
fn to_tokens(&self, tokens: &mut TokenStream) {
self.0.to_tokens(tokens)
}
}
/// Note that the 'type' keyword is handled separately in `syn`. It's not an `Ident`:
impl Parse for SimpleIdent {
fn parse(input: ParseStream) -> syn::Result<Self> {
@ -276,7 +270,7 @@ impl JSONObject {
let mut elems = HashMap::with_capacity(map_elems.len());
for c in map_elems {
if elems.insert(c.key.clone().into(), c.value).is_some() {
bail!(&c.key => "duplicate '{}' in schema", c.key);
bail!(c.key.span(), "duplicate '{}' in schema", c.key);
}
}
Ok(elems)