Skip to content

fix(lambda-rs-args): Optimize parsed argument lookup and positional argument assignment#189

Merged
vmarcella merged 5 commits intomainfrom
vmarcella/optimize-parser
Mar 4, 2026
Merged

fix(lambda-rs-args): Optimize parsed argument lookup and positional argument assignment#189
vmarcella merged 5 commits intomainfrom
vmarcella/optimize-parser

Conversation

@vmarcella
Copy link
Member

Summary

Speed up lambda-rs-args parsing results and improve docs to match lambda-rs rustdoc conventions.

Related Issues

Relates to: (none)

Changes

  • Build an index for ParsedArgs so has() / get_*() are O(1) by name instead of scanning.
  • Track a positional cursor so positional assignment after -- is O(p) total instead of O(p^2).
  • Update rustdoc for the touched APIs/helpers using # Arguments / # Returns / # Errors / # Panics sections.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (updates to docs, specs, tutorials, or comments)
  • Refactor (code change that neither fixes a bug nor adds a feature)
  • Performance (change that improves performance)
  • Test (adding or updating tests)
  • Build/CI (changes to build process or CI configuration)

Affected Crates

  • lambda-rs
  • lambda-rs-platform
  • lambda-rs-args
  • lambda-rs-logging
  • Other:

Checklist

  • Code follows the repository style guidelines (cargo +nightly fmt --all)
  • Code passes clippy (cargo clippy --workspace --all-targets -- -D warnings)
  • Tests pass (cargo test --workspace)
  • New code includes appropriate documentation
  • Public API changes are documented
  • Breaking changes are noted in this PR description

Testing

Commands run:

cargo test -p lambda-rs-args

Manual verification steps (if applicable):

  1. N/A

Screenshots/Recordings

N/A

Platform Testing

  • macOS
  • Windows
  • Linux

Additional Notes

@vmarcella vmarcella requested a review from Copilot March 3, 2026 21:54
@vmarcella vmarcella changed the title Vmarcella/optimize parser fix(lambda-rs-args): Optimize parsed argument lookup and positional argument assignment Mar 3, 2026
@github-actions
Copy link

github-actions bot commented Mar 3, 2026

✅ Coverage Report

📊 View Full HTML Report (download artifact)

Overall Coverage

Metric Value
Total Line Coverage 76.71%
Lines Covered 12528 / 16331

Changed Files in This PR

File Coverage Lines
crates/lambda-rs-args/src/lib.rs 75.35% 743/986

PR Files Coverage: 75.35% (743/986 lines)


Generated by cargo-llvm-cov · Latest main coverage

Last updated: 2026-03-04 19:10:14 UTC · Commit: 27511d1

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes lambda-rs-args runtime argument lookup and positional assignment performance, while updating rustdoc to follow the repository’s sectioned documentation style.

Changes:

  • Build a name→index map inside ParsedArgs so has() / get_*() are O(1) instead of scanning the parsed vector.
  • Track a positional cursor for assigning values after --, avoiding repeated rescans of positionals.
  • Expand/standardize rustdoc for parse, compile, ParsedArgs getters, and add a targeted test for has() behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

/// Returns a count value by name, if present and typed as integer.
///
/// # Arguments
/// - `name`: The declared argument name (for example, `"-v"`).
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_count's doc example uses "-v" as the lookup name, but has() (and the parse docs) explicitly state that aliases like -p are not resolved at lookup time and callers should use the declared/canonical name. Consider changing the example to a canonical long name (e.g. "--verbose") or clarifying that "-v" is only correct when it is the declared name rather than an alias.

Suggested change
/// - `name`: The declared argument name (for example, `"-v"`).
/// - `name`: The declared argument name (for example, `"--verbose"`).

Copilot uses AI. Check for mistakes.
Comment on lines +440 to +447
/// # Errors
/// Returns `ArgsError` when:
/// - `--help` / `-h` is present (`ArgsError::HelpRequested`).
/// - An unknown argument is encountered in strict mode.
/// - A value is missing for a value-taking argument.
/// - A value fails type parsing.
/// - A required argument is not provided.
/// - Mutually exclusive or requires relationships are violated.
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parse rustdoc mentions "unknown argument ... in strict mode", but the API surface here is ignore_unknown(bool) and there is no named "strict mode" concept elsewhere in this crate. Consider rewording this bullet to explicitly reference ignore_unknown(false) (default) vs ignore_unknown(true) to avoid ambiguity.

Copilot uses AI. Check for mistakes.
Comment on lines +448 to +452
///
/// - Aliases are resolved during parsing; lookups on `ParsedArgs` use the
/// declared argument name (canonical form), not an alias.
/// - Combined short flags like `-vvv` are supported only for `Count` and
/// `Boolean` arguments.
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the parse rustdoc, the last two bullets are behavior notes (alias resolution / clustered short flags), not error conditions, but they currently live under the # Errors section. Moving these into a separate section (e.g. # Notes/# Behavior) would make the docs clearer and more consistent with rustdoc section semantics.

Copilot uses AI. Check for mistakes.
@vmarcella vmarcella merged commit b134676 into main Mar 4, 2026
10 checks passed
@vmarcella vmarcella deleted the vmarcella/optimize-parser branch March 4, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants