mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-07 22:33:12 +00:00
api-macro: relax Fieldname rules
by replacing more characters ('.','+') by '_' and prefix them when it starts with a number we sometimes need to parse such fields, e.g in serde attributes like #[serde(rename = "802.3ad")] Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
29763449f0
commit
958e72aa69
@ -29,7 +29,11 @@ pub struct FieldName {
|
|||||||
|
|
||||||
impl FieldName {
|
impl FieldName {
|
||||||
pub fn new(name: String, span: Span) -> Self {
|
pub fn new(name: String, span: Span) -> Self {
|
||||||
let ident_str = name.replace("-", "_");
|
let mut ident_str = name.replace(['-', '.', '+'].as_ref(), "_");
|
||||||
|
|
||||||
|
if ident_str.chars().next().unwrap().is_numeric() {
|
||||||
|
ident_str.insert(0, '_');
|
||||||
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
ident: Ident::new(&ident_str, span),
|
ident: Ident::new(&ident_str, span),
|
||||||
|
Loading…
Reference in New Issue
Block a user