From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 2/2] api-macro: relax Fieldname rules
Date: Wed, 16 Sep 2020 14:09:45 +0200 [thread overview]
Message-ID: <20200916120945.12073-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20200916120945.12073-1-d.csapak@proxmox.com>
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>
---
proxmox-api-macro/src/util.rs | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/proxmox-api-macro/src/util.rs b/proxmox-api-macro/src/util.rs
index 6ac39c2..9748131 100644
--- a/proxmox-api-macro/src/util.rs
+++ b/proxmox-api-macro/src/util.rs
@@ -29,7 +29,11 @@ pub struct FieldName {
impl FieldName {
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 {
ident: Ident::new(&ident_str, span),
--
2.20.1
next prev parent reply other threads:[~2020-09-16 12:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-16 12:09 [pbs-devel] [PATCH proxmox 1/2] api-macro: fix broken binary ident search Dominik Csapak
2020-09-16 12:09 ` Dominik Csapak [this message]
2020-09-17 4:25 ` Dietmar Maurer
2020-09-17 6:34 ` Dietmar Maurer
2020-09-17 6:37 ` [pbs-devel] applied: " Dietmar Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200916120945.12073-2-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox