diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-03-10 12:55:21 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-03-10 12:55:21 +0100 |
| commit | 62f35602a87574dcc607f1637aeae1be574981ff (patch) | |
| tree | 363a1918006e06d7d79dc2ace5f8e59cd3b6bb19 /macros/src/util.rs | |
| parent | c38d72383d2068361d635d6c1c78ba97aa917801 (diff) | |
New #[func] macro
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), + } +} |
