mirror of
https://git.proxmox.com/git/proxmox
synced 2025-06-15 18:27:35 +00:00
api-macro: remove Into<Ident> for SimpleIdent
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
d3ec63f26d
commit
02acd7269f
@ -90,7 +90,7 @@ impl TryFrom<JSONObject> for Schema {
|
|||||||
properties: obj.into_iter().try_fold(
|
properties: obj.into_iter().try_fold(
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
|mut properties, (key, value)| -> Result<_, syn::Error> {
|
|mut properties, (key, value)| -> Result<_, syn::Error> {
|
||||||
properties.push((Ident::from(key), value.try_into()?));
|
properties.push((key.into_ident()?, value.try_into()?));
|
||||||
Ok(properties)
|
Ok(properties)
|
||||||
},
|
},
|
||||||
)?,
|
)?,
|
||||||
|
@ -10,6 +10,13 @@ use syn::spanned::Spanned;
|
|||||||
use syn::Token;
|
use syn::Token;
|
||||||
|
|
||||||
/// A more relaxed version of Ident which allows hyphens.
|
/// A more relaxed version of Ident which allows hyphens.
|
||||||
|
///
|
||||||
|
/// Note that this acts both as an Ident and as a String so that we can easily access an &str
|
||||||
|
/// (which Ident does not provide, instead, Ident always requires you to produce a newly owned
|
||||||
|
/// `String`).
|
||||||
|
/// Because of this the user also needs to be aware of the differences between idents and strings,
|
||||||
|
/// and therefore we do not implement `Into<Ident>` anymore, but the user needs to explicitly ask
|
||||||
|
/// for it via the `.into_ident()` method.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SimpleIdent(Ident, String);
|
pub struct SimpleIdent(Ident, String);
|
||||||
|
|
||||||
@ -23,6 +30,19 @@ impl SimpleIdent {
|
|||||||
&self.1
|
&self.1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub unsafe fn into_ident_unchecked(self) -> Ident {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn into_ident(self) -> Result<Ident, syn::Error> {
|
||||||
|
if self.1.as_bytes().contains(&b'-') {
|
||||||
|
bail!(self.0 => "invalid identifier: '{}'", self.1);
|
||||||
|
}
|
||||||
|
Ok(unsafe { self.into_ident_unchecked() })
|
||||||
|
}
|
||||||
|
|
||||||
//#[inline]
|
//#[inline]
|
||||||
//pub fn span(&self) -> Span {
|
//pub fn span(&self) -> Span {
|
||||||
// self.0.span()
|
// self.0.span()
|
||||||
@ -50,12 +70,6 @@ impl From<Ident> for SimpleIdent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SimpleIdent> for Ident {
|
|
||||||
fn from(this: SimpleIdent) -> Ident {
|
|
||||||
this.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for SimpleIdent {
|
impl fmt::Display for SimpleIdent {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
fmt::Display::fmt(&self.0, f)
|
fmt::Display::fmt(&self.0, f)
|
||||||
|
Loading…
Reference in New Issue
Block a user