diff options
Diffstat (limited to 'macros/src/util.rs')
| -rw-r--r-- | macros/src/util.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/macros/src/util.rs b/macros/src/util.rs index c8c56a05..d94ba932 100644 --- a/macros/src/util.rs +++ b/macros/src/util.rs @@ -58,14 +58,6 @@ pub fn kebab_case(name: &Ident) -> String { name.to_string().to_lowercase().replace('_', "-") } -/// Dedent documentation text. -pub fn dedent(text: &str) -> String { - text.lines() - .map(|s| s.strip_prefix(" ").unwrap_or(s)) - .collect::<Vec<_>>() - .join("\n") -} - /// Extract documentation comments from an attribute list. pub fn documentation(attrs: &[syn::Attribute]) -> String { let mut doc = String::new(); @@ -86,3 +78,11 @@ pub fn documentation(attrs: &[syn::Attribute]) -> String { doc.trim().into() } + +/// Extract a line of metadata from documentation. +pub fn meta_line<'a>(lines: &mut Vec<&'a str>, key: &str) -> Result<&'a str> { + match lines.pop().and_then(|line| line.strip_prefix(&format!("{key}:"))) { + Some(value) => Ok(value.trim()), + None => bail!(callsite, "missing metadata key: {}", key), + } +} |
