From 05a5640f107fcd6dd210ea8df4d9440786a0ac4a Mon Sep 17 00:00:00 2001 From: Jay Oster Date: Sat, 10 Feb 2024 17:06:00 -0600 Subject: [PATCH] Update dependencies (#22) Updates `myn` to 0.2 and `onlyerror` to 0.1.4. Fixes indentation on doc comments processed by `onlyargs_derive`. --- Cargo.lock | 8 ++++---- onlyargs_derive/Cargo.toml | 2 +- onlyargs_derive/src/parser.rs | 26 ++++++++++++++++++++------ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d8a0a9..0277216 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,9 +37,9 @@ dependencies = [ [[package]] name = "myn" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950af707b8005ae33bb0f0b20cb32b09750e7375085606dc45b2f2078a34e52" +checksum = "531b2675eec9b104037d42e9045a0ea5c27c8727bdc8e1f55c93bb088f1dec07" [[package]] name = "onlyargs" @@ -58,9 +58,9 @@ dependencies = [ [[package]] name = "onlyerror" -version = "0.1.0" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3de62063c9f7ef82b259f3530af425d0b8bba375c7f790087616d8a613b5f8bc" +checksum = "8c26d4ea2ccd9b7acedc478853805606e60c5b7b7aedfc1c54ed6d1fdc0587db" dependencies = [ "myn", ] diff --git a/onlyargs_derive/Cargo.toml b/onlyargs_derive/Cargo.toml index 6db34d2..160ddce 100644 --- a/onlyargs_derive/Cargo.toml +++ b/onlyargs_derive/Cargo.toml @@ -14,5 +14,5 @@ license = "MIT" proc-macro = true [dependencies] -myn = "0.1" +myn = "0.2" onlyargs = { version = "0.1", path = ".." } diff --git a/onlyargs_derive/src/parser.rs b/onlyargs_derive/src/parser.rs index 6aa783e..b432f32 100644 --- a/onlyargs_derive/src/parser.rs +++ b/onlyargs_derive/src/parser.rs @@ -58,7 +58,7 @@ impl ArgumentStruct { input.parse_visibility()?; input.expect_ident("struct")?; - let name = input.as_ident()?; + let name = input.try_ident()?; let content = input.expect_group(Delimiter::Brace)?; let fields = Argument::parse(content)?; @@ -82,7 +82,10 @@ impl ArgumentStruct { } } - let doc = get_doc_comment(&attrs); + let doc = get_doc_comment(&attrs) + .into_iter() + .map(trim_with_indent) + .collect(); match input.next() { None => Ok(Self { @@ -105,7 +108,10 @@ impl Argument { let attrs = input.parse_attributes()?; // Parse attributes - let doc = get_doc_comment(&attrs); + let doc = get_doc_comment(&attrs) + .into_iter() + .map(trim_with_indent) + .collect(); let mut default = None; let mut long = false; let mut short = None; @@ -116,12 +122,12 @@ impl Argument { "default" => { let mut stream = attr.tree.expect_group(Delimiter::Parenthesis)?; - default = Some(stream.as_lit()?); + default = Some(stream.try_lit()?); } "long" => long = true, "short" => { let mut stream = attr.tree.expect_group(Delimiter::Parenthesis)?; - let lit = stream.as_lit()?; + let lit = stream.try_lit()?; short = Some(lit.as_char()?); } @@ -130,7 +136,7 @@ impl Argument { } input.parse_visibility()?; - let name = input.as_ident()?; + let name = input.try_ident()?; input.expect_punct(':')?; let (path, span) = input.parse_path()?; let _ = input.expect_punct(','); @@ -353,3 +359,11 @@ impl ArgType { } } } + +#[allow(clippy::needless_pass_by_value)] +fn trim_with_indent(line: String) -> String { + line.strip_prefix(' ') + .unwrap_or(&line) + .trim_end() + .to_string() +}