mirror of
https://git.proxmox.com/git/proxmox
synced 2025-05-01 11:47:49 +00:00
api-macro: util: add join and join_debug helper
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
0b2c9b95b4
commit
2c83d55cb0
@ -188,14 +188,7 @@ fn handle_regular_struct(
|
|||||||
|
|
||||||
// now error out about all the fields not found in the struct:
|
// now error out about all the fields not found in the struct:
|
||||||
if !schema_fields.is_empty() {
|
if !schema_fields.is_empty() {
|
||||||
let bad_fields = schema_fields.keys().fold(String::new(), |mut acc, key| {
|
let bad_fields = util::join(", ", schema_fields.keys());
|
||||||
if !acc.is_empty() {
|
|
||||||
acc.push_str(", ");
|
|
||||||
acc
|
|
||||||
} else {
|
|
||||||
key.to_owned()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
bail!(
|
bail!(
|
||||||
schema.span,
|
schema.span,
|
||||||
"struct does not contain the following fields: {}",
|
"struct does not contain the following fields: {}",
|
||||||
|
@ -542,3 +542,31 @@ impl Parse for AttrArgs {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Join an iterator over `Display` values.
|
||||||
|
pub fn join<T>(separator: &str, iter: impl Iterator<Item = T>) -> String
|
||||||
|
where
|
||||||
|
T: std::fmt::Display,
|
||||||
|
{
|
||||||
|
let mut text = String::new();
|
||||||
|
let mut sep = "";
|
||||||
|
for i in iter {
|
||||||
|
text = format!("{}{}{}", text, sep, i);
|
||||||
|
sep = separator;
|
||||||
|
}
|
||||||
|
text
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Join an iterator over `Debug` values.
|
||||||
|
pub fn join_debug<T>(separator: &str, iter: impl Iterator<Item = T>) -> String
|
||||||
|
where
|
||||||
|
T: std::fmt::Debug,
|
||||||
|
{
|
||||||
|
let mut text = String::new();
|
||||||
|
let mut sep = "";
|
||||||
|
for i in iter {
|
||||||
|
text = format!("{}{}{:?}", text, sep, i);
|
||||||
|
sep = separator;
|
||||||
|
}
|
||||||
|
text
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user