Skip to content

Fix nightly warnings about lifetimes - #25

Merged
kaidokert merged 3 commits into
mainfrom
lifetime_cleanup
Jul 3, 2025
Merged

Fix nightly warnings about lifetimes#25
kaidokert merged 3 commits into
mainfrom
lifetime_cleanup

Conversation

@kaidokert

@kaidokert kaidokert commented Jul 3, 2025

Copy link
Copy Markdown
Owner

Also allow optional no-fmt compilation of demos

Summary by Sourcery

Enable building demos without the ufmt feature, fix nightly compiler warnings by parameterizing parser events with explicit lifetimes, and improve demo JSON status handling.

New Features:

  • Allow demos to compile without the ufmt feature by stubbing the uwriteln! macro and conditionally initializing serial.

Bug Fixes:

  • Add explicit lifetimes to picojson parser methods and PullParser trait to address nightly compiler warnings.

Enhancements:

  • Use safe slice.get_mut and UTF-8 conversion for status parsing in demos and include status output in logs.

Summary by CodeRabbit

  • New Features

    • Added debug output for parsed status strings after JSON parsing in demo examples.
  • Bug Fixes

    • Improved safety when handling and extracting strings from parsed JSON, reducing the risk of panics.
  • Refactor

    • Updated several method and trait signatures to include explicit lifetime annotations for improved type safety and correctness.
    • Made serial interface initialization and macro imports conditional based on feature flags for better flexibility.
    • Included the "ufmt" feature in all test configurations to standardize testing environments.

Also allow optional no-fmt compilation of demos
@sourcery-ai

sourcery-ai Bot commented Jul 3, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR refines picojson’s parser APIs by adding explicit lifetimes to Event returns to satisfy the compiler, and enhances the AVR demo examples with optional no-fmt support and safer status handling in JSON parsing.

Class diagram for updated Event and PullParser lifetimes

classDiagram
    class Event {
        <<lifetime: 'a, 'b>>
        // ... (fields omitted)
    }
    class PullParser {
        +next(&mut self) -> Option<Result<Event<'_, '_>, ParseError>>
        +next_event(&mut self) -> Result<Event<'_, '_>, ParseError>
    }
    class StreamParser {
        <<lifetime: 'b, R, C>>
        +next_event_impl(&mut self) -> Result<Event<'_, '_>, ParseError>
        +extract_number_from_state(&mut self) -> Result<Event<'_, '_>, ParseError>
        +extract_string_from_state(&mut self) -> Result<Event<'_, '_>, ParseError>
        +create_unescaped_string(&mut self) -> Result<Event<'_, '_>, ParseError>
        +create_borrowed_string(&mut self, start_pos: usize) -> Result<Event<'_, '_>, ParseError>
        +extract_key_from_state(&mut self) -> Result<Event<'_, '_>, ParseError>
        +create_unescaped_key(&mut self) -> Result<Event<'_, '_>, ParseError>
        +create_borrowed_key(&mut self, start_pos: usize) -> Result<Event<'_, '_>, ParseError>
        +extract_number_from_state_with_context(&mut self, from_container_end: bool) -> Result<Event<'_, '_>, ParseError>
    }
    class SliceParser {
        <<lifetime: 'a, 'b, C>>
        +parse_number_event(&mut self, start: usize, from_container_end: bool) -> Result<Event<'_, '_>, ParseError>
        +handle_simple_escape_token(&mut self, escape_token: &EventToken) -> Result<Option<Event<'_, '_>>, ParseError>
        +handle_escape_event(&mut self, escape_char: u8) -> Result<Option<Event<'_, '_>>, ParseError>
        +next_event_impl(&mut self) -> Result<Event<'_, '_>, ParseError>
    }
    class CopyOnEscape {
        <<lifetime: 'a, 'b>>
        +end_string(&mut self, pos: usize) -> Result<String<'_, '_>, ParseError>
    }
    class NumberParser {
        +parse_number_event<T: NumberExtractor>(extractor: &T, start_pos: usize, from_container_end: bool) -> Result<Event<'_, '_>, ParseError>
    }
    PullParser <|.. StreamParser
    PullParser <|.. SliceParser
Loading

Class diagram for Event and String with explicit lifetimes

classDiagram
    class Event {
        <<lifetime: 'a, 'b>>
        // ... (fields omitted)
    }
    class String {
        <<lifetime: 'a, 'b>>
        // ... (fields omitted)
    }
    class CopyOnEscape {
        +end_string(&mut self, pos: usize) -> Result<String<'a, 'b>, ParseError>
    }
    Event <.. CopyOnEscape : returns
    String <.. CopyOnEscape : returns
Loading

Class diagram for PullParser trait with updated next and next_event methods

classDiagram
    class PullParser {
        +next(&mut self) -> Option<Result<Event<'_, '_>, ParseError>>
        +next_event(&mut self) -> Result<Event<'_, '_>, ParseError>
    }
    class StreamParser
    class SliceParser
    PullParser <|.. StreamParser
    PullParser <|.. SliceParser
Loading

File-Level Changes

Change Details Files
Add explicit lifetimes to Event return types in picojson parsers
  • Update signature of next_event_impl, extract_, create_ methods to Result<Event<', '>, ParseError>
  • Adjust PullParser trait and next() iterator to propagate lifetimes
  • Change CopyOnEscape end_string and number_parser parse_number_event to return Event<', '>
picojson/src/stream_parser.rs
picojson/src/slice_parser.rs
picojson/src/shared.rs
picojson/src/copy_on_escape.rs
picojson/src/number_parser.rs
Enable optional no-fmt compilation in AVR demo examples
  • Feature-gate ufmt imports and stub uwriteln! macro when feature disabled
  • Wrap serial initialization behind ufmt feature flag
avr_demo/examples/test_picojson.rs
avr_demo/examples/test_serde.rs
Improve JSON status extraction safety and logging in demos
  • Replace slice indexing and unwrap with get_mut and from_utf8 checks
  • Introduce status_str fallback and print parsed status
avr_demo/examples/test_picojson.rs
avr_demo/examples/test_serde.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jul 3, 2025

Copy link
Copy Markdown

"""

Walkthrough

This update introduces explicit lifetime annotations to the Event type across several parser modules, refining function and trait method signatures without altering logic or control flow. Additionally, the AVR demo examples are updated for safer buffer handling, conditional macro imports, and improved debug output, with serial interface initialization now gated by feature flags. The test suite configurations are also adjusted to enable the "ufmt" feature consistently.

Changes

File(s) Change Summary
picojson/src/copy_on_escape.rs Updated CopyOnEscape::end_string return type to Result<String<'_, '_>, ParseError> with explicit lifetimes.
picojson/src/number_parser.rs Changed parse_number_event return type to Result<Event<'_, '_>, ParseError> with explicit lifetimes.
picojson/src/shared.rs Updated PullParser trait method signatures to return Event<'_, '_> with explicit lifetimes.
picojson/src/slice_parser.rs, picojson/src/stream_parser.rs Multiple internal and trait method signatures updated to return Event<'_, '_> with explicit lifetimes.
avr_demo/examples/test_picojson.rs, avr_demo/examples/test_serde.rs Conditional macro imports for uwriteln!, safer buffer handling, serial interface gated by feature flags, and improved debug output.
avr_demo/run_suite.py Added "ufmt" feature to all test configurations in the CONFIGS list for consistent feature enabling.

Sequence Diagram(s)

sequenceDiagram
    participant Main as main()
    participant Serial as Serial (optional)
    participant Parser as Parser
    participant Buffer as Scratch Buffer

    Main->>Parser: Parse JSON input
    Parser->>Buffer: Copy/extract "status" safely
    Parser-->>Main: Return parse result
    alt Serial enabled (ufmt feature)
        Main->>Serial: Initialize Serial
        Main->>Serial: Print parse result and status
    else Serial disabled
        Main->>Main: No serial output
    end
Loading

Possibly related PRs

  • Add avr tests #18: Adds the avr_demo crate, including test_picojson.rs and related AVR build/test infrastructure, directly relating to the example code updated in this PR.
  • Panic notes #21: Focuses on removing panic-inducing unwraps and improving JSON parsing safety in picojson, closely related to the safer buffer handling changes in test_picojson.rs.
  • New clean api #6: Involves API redesign affecting ArrayBitStack and parser construction, closely related to example usage changes in this PR.

Poem

In the parser's warren, lifetimes now gleam,
Each function and trait with a well-borrowed theme.
AVR bunnies hop with safer string delight,
Serial dreams appear only when the features are right.
With a nibble and a wink,
Our JSONs never stink!
🐇✨
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary of Changes

Hello @kaidokert, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request primarily addresses compiler warnings encountered with nightly Rust builds by explicitly defining lifetimes for data types within the picojson library. It also enhances the flexibility of demo application builds by allowing them to compile without the ufmt feature, which disables serial output. Minor improvements to demo output and slice handling are also included.

Highlights

  • Lifetime Fixes: Explicitly specified lifetimes for Event and String types in various methods across the picojson crate (copy_on_escape.rs, number_parser.rs, shared.rs, slice_parser.rs, stream_parser.rs) to resolve nightly compiler warnings related to lifetime inference.
  • Conditional Demo Compilation: Introduced conditional compilation (#[cfg(feature = "ufmt")]) and a stub macro for uwriteln! in avr_demo/examples/test_picojson.rs and avr_demo/examples/test_serde.rs. This allows the demo applications to be compiled without the ufmt feature, effectively disabling serial output when ufmt is not enabled.
  • Safer Slice Access: Improved robustness in avr_demo/examples/test_picojson.rs by changing direct slice access (scratch[..status_len]) to use scratch.get_mut(..status_len), preventing potential panics if the requested slice goes out of bounds.
  • Enhanced Demo Output: Added printing of the parsed status field to the serial output in both avr_demo/examples/test_picojson.rs and avr_demo/examples/test_serde.rs.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey @kaidokert - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses several points: it fixes nightly compiler warnings by specifying explicit lifetimes, allows demo applications to be built without the ufmt feature, and enhances the safety of JSON parsing in the demos. The lifetime fixes are applied consistently across the picojson crate. The conditional compilation for ufmt is well-handled with a macro stub. The safety improvements in the demo code, such as using get_mut and get to avoid potential panics, are excellent. I have one suggestion to improve code conciseness.

Comment thread avr_demo/examples/test_picojson.rs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
picojson/src/slice_parser.rs (1)

196-200: handle_escape_event keeps returning Ok(None) – consider Result<(), _>

handle_escape_event will never propagate an Event, yet its return type is Result<Option<Event<'_, '_>>, ParseError>.
Changing it to Result<(), ParseError> would simplify the call-site pattern‐matching that always discards the None.

-fn handle_escape_event(
-    &mut self,
-    escape_char: u8,
-) -> Result<Option<Event<'_, '_>>, ParseError> {
+fn handle_escape_event(
+    &mut self,
+    escape_char: u8,
+) -> Result<(), ParseError> {-    Ok(None)
+    Ok(())
 }
picojson/src/stream_parser.rs (1)

127-131: Consistent lifetime annotations, but consider a local alias

Every internal helper now repeats Result<Event<'_, '_>, ParseError>.
A single type alias would reduce noise and future diff size:

 use crate::shared::{ContentRange, Event, ParseError, …};
+type JsonEvent<'a, 'b> = Event<'a, 'b>;-fn next_event_impl(&mut self) -> Result<Event<'_, '_>, ParseError> {
+fn next_event_impl(&mut self) -> Result<JsonEvent<'_, '_>, ParseError> {

Optional, but improves readability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e8c0f7 and a49b98b.

📒 Files selected for processing (7)
  • avr_demo/examples/test_picojson.rs (4 hunks)
  • avr_demo/examples/test_serde.rs (3 hunks)
  • picojson/src/copy_on_escape.rs (1 hunks)
  • picojson/src/number_parser.rs (1 hunks)
  • picojson/src/shared.rs (1 hunks)
  • picojson/src/slice_parser.rs (5 hunks)
  • picojson/src/stream_parser.rs (7 hunks)
🧰 Additional context used
🧠 Learnings (7)
picojson/src/number_parser.rs (3)
Learnt from: kaidokert
PR: kaidokert/picojson-rs#1
File: tokenizer/src/bitstack/mod.rs:0-0
Timestamp: 2025-06-28T23:43:22.754Z
Learning: In the picojson-rs project, the BitStack trait was redesigned to return bool instead of Option<bool> for pop() and top() methods. Empty stacks return false rather than None, which simplifies the API and avoids Option handling.
Learnt from: kaidokert
PR: kaidokert/picojson-rs#5
File: picojson/src/lib.rs:0-0
Timestamp: 2025-06-29T17:48:18.188Z
Learning: In the picojson-rs project, the `use tokenizer as ujson;` alias in lib.rs is a transitionary and fully internal private alias used during crate reorganization. Examples and external code no longer depend on this alias, making the private visibility appropriate.
Learnt from: kaidokert
PR: kaidokert/picojson-rs#1
File: stax/src/flex_parser.rs:0-0
Timestamp: 2025-06-28T18:12:29.968Z
Learning: In the stax JSON parser codebase, EscapeSequence event handlers exist in flex_parser.rs not because they're needed by that parser variant, but to avoid catch-all patterns in match statements. The flex parser doesn't need to process EscapeSequence events, but the other parser variant (direct parser) does need them.
picojson/src/shared.rs (3)
Learnt from: kaidokert
PR: kaidokert/picojson-rs#1
File: tokenizer/src/bitstack/mod.rs:0-0
Timestamp: 2025-06-28T23:43:22.754Z
Learning: In the picojson-rs project, the BitStack trait was redesigned to return bool instead of Option<bool> for pop() and top() methods. Empty stacks return false rather than None, which simplifies the API and avoids Option handling.
Learnt from: kaidokert
PR: kaidokert/picojson-rs#5
File: picojson/src/lib.rs:0-0
Timestamp: 2025-06-29T17:48:18.188Z
Learning: In the picojson-rs project, the `use tokenizer as ujson;` alias in lib.rs is a transitionary and fully internal private alias used during crate reorganization. Examples and external code no longer depend on this alias, making the private visibility appropriate.
Learnt from: kaidokert
PR: kaidokert/picojson-rs#1
File: stax/src/flex_parser.rs:0-0
Timestamp: 2025-06-28T18:12:29.968Z
Learning: In the stax JSON parser codebase, EscapeSequence event handlers exist in flex_parser.rs not because they're needed by that parser variant, but to avoid catch-all patterns in match statements. The flex parser doesn't need to process EscapeSequence events, but the other parser variant (direct parser) does need them.
avr_demo/examples/test_picojson.rs (4)
Learnt from: kaidokert
PR: kaidokert/picojson-rs#1
File: tokenizer/src/bitstack/mod.rs:0-0
Timestamp: 2025-06-28T23:43:22.754Z
Learning: In the picojson-rs project, the BitStack trait was redesigned to return bool instead of Option<bool> for pop() and top() methods. Empty stacks return false rather than None, which simplifies the API and avoids Option handling.
Learnt from: kaidokert
PR: kaidokert/picojson-rs#5
File: picojson/src/lib.rs:0-0
Timestamp: 2025-06-29T17:48:18.188Z
Learning: In the picojson-rs project, the `use tokenizer as ujson;` alias in lib.rs is a transitionary and fully internal private alias used during crate reorganization. Examples and external code no longer depend on this alias, making the private visibility appropriate.
Learnt from: kaidokert
PR: kaidokert/picojson-rs#1
File: stax/src/lib.rs:19-21
Timestamp: 2025-06-28T18:14:22.845Z
Learning: In Rust crate organization, functions can be imported into lib.rs via `use` statements not for direct usage within lib.rs itself, but to make them available to other modules within the same crate via the `crate::` path. This is a valid pattern and such imports should not be flagged as unused even if lib.rs doesn't directly call them.
Learnt from: kaidokert
PR: kaidokert/picojson-rs#18
File: avr_demo/src/stack_measurement.rs:39-39
Timestamp: 2025-07-02T06:17:39.995Z
Learning: In AVR stack measurement implementations for ATmega2560, when the stack grows downward from RAMEND and watermark scanning finds the first overwritten byte at current_ptr, the calculation `RAMEND_ADDR - current_ptr` correctly reports actual stack usage (bytes consumed), not remaining bytes. This pattern is used in the picojson-rs avr_demo stack measurement module.
avr_demo/examples/test_serde.rs (4)
Learnt from: kaidokert
PR: kaidokert/picojson-rs#5
File: picojson/src/lib.rs:0-0
Timestamp: 2025-06-29T17:48:18.188Z
Learning: In the picojson-rs project, the `use tokenizer as ujson;` alias in lib.rs is a transitionary and fully internal private alias used during crate reorganization. Examples and external code no longer depend on this alias, making the private visibility appropriate.
Learnt from: kaidokert
PR: kaidokert/picojson-rs#1
File: tokenizer/src/bitstack/mod.rs:0-0
Timestamp: 2025-06-28T23:43:22.754Z
Learning: In the picojson-rs project, the BitStack trait was redesigned to return bool instead of Option<bool> for pop() and top() methods. Empty stacks return false rather than None, which simplifies the API and avoids Option handling.
Learnt from: kaidokert
PR: kaidokert/picojson-rs#1
File: stax/src/lib.rs:19-21
Timestamp: 2025-06-28T18:14:22.845Z
Learning: In Rust crate organization, functions can be imported into lib.rs via `use` statements not for direct usage within lib.rs itself, but to make them available to other modules within the same crate via the `crate::` path. This is a valid pattern and such imports should not be flagged as unused even if lib.rs doesn't directly call them.
Learnt from: kaidokert
PR: kaidokert/picojson-rs#18
File: avr_demo/src/stack_measurement.rs:39-39
Timestamp: 2025-07-02T06:17:39.995Z
Learning: In AVR stack measurement implementations for ATmega2560, when the stack grows downward from RAMEND and watermark scanning finds the first overwritten byte at current_ptr, the calculation `RAMEND_ADDR - current_ptr` correctly reports actual stack usage (bytes consumed), not remaining bytes. This pattern is used in the picojson-rs avr_demo stack measurement module.
picojson/src/copy_on_escape.rs (3)
Learnt from: kaidokert
PR: kaidokert/picojson-rs#1
File: tokenizer/src/bitstack/mod.rs:0-0
Timestamp: 2025-06-28T23:43:22.754Z
Learning: In the picojson-rs project, the BitStack trait was redesigned to return bool instead of Option<bool> for pop() and top() methods. Empty stacks return false rather than None, which simplifies the API and avoids Option handling.
Learnt from: kaidokert
PR: kaidokert/picojson-rs#5
File: picojson/src/lib.rs:0-0
Timestamp: 2025-06-29T17:48:18.188Z
Learning: In the picojson-rs project, the `use tokenizer as ujson;` alias in lib.rs is a transitionary and fully internal private alias used during crate reorganization. Examples and external code no longer depend on this alias, making the private visibility appropriate.
Learnt from: kaidokert
PR: kaidokert/picojson-rs#1
File: stax/src/flex_parser.rs:0-0
Timestamp: 2025-06-28T18:12:29.968Z
Learning: In the stax JSON parser codebase, EscapeSequence event handlers exist in flex_parser.rs not because they're needed by that parser variant, but to avoid catch-all patterns in match statements. The flex parser doesn't need to process EscapeSequence events, but the other parser variant (direct parser) does need them.
picojson/src/slice_parser.rs (3)
Learnt from: kaidokert
PR: kaidokert/picojson-rs#1
File: stax/src/flex_parser.rs:0-0
Timestamp: 2025-06-28T18:12:29.968Z
Learning: In the stax JSON parser codebase, EscapeSequence event handlers exist in flex_parser.rs not because they're needed by that parser variant, but to avoid catch-all patterns in match statements. The flex parser doesn't need to process EscapeSequence events, but the other parser variant (direct parser) does need them.
Learnt from: kaidokert
PR: kaidokert/picojson-rs#1
File: tokenizer/src/bitstack/mod.rs:0-0
Timestamp: 2025-06-28T23:43:22.754Z
Learning: In the picojson-rs project, the BitStack trait was redesigned to return bool instead of Option<bool> for pop() and top() methods. Empty stacks return false rather than None, which simplifies the API and avoids Option handling.
Learnt from: kaidokert
PR: kaidokert/picojson-rs#5
File: picojson/src/lib.rs:0-0
Timestamp: 2025-06-29T17:48:18.188Z
Learning: In the picojson-rs project, the `use tokenizer as ujson;` alias in lib.rs is a transitionary and fully internal private alias used during crate reorganization. Examples and external code no longer depend on this alias, making the private visibility appropriate.
picojson/src/stream_parser.rs (3)
Learnt from: kaidokert
PR: kaidokert/picojson-rs#1
File: stax/src/flex_parser.rs:0-0
Timestamp: 2025-06-28T18:12:29.968Z
Learning: In the stax JSON parser codebase, EscapeSequence event handlers exist in flex_parser.rs not because they're needed by that parser variant, but to avoid catch-all patterns in match statements. The flex parser doesn't need to process EscapeSequence events, but the other parser variant (direct parser) does need them.
Learnt from: kaidokert
PR: kaidokert/picojson-rs#1
File: tokenizer/src/bitstack/mod.rs:0-0
Timestamp: 2025-06-28T23:43:22.754Z
Learning: In the picojson-rs project, the BitStack trait was redesigned to return bool instead of Option<bool> for pop() and top() methods. Empty stacks return false rather than None, which simplifies the API and avoids Option handling.
Learnt from: kaidokert
PR: kaidokert/picojson-rs#5
File: picojson/src/lib.rs:0-0
Timestamp: 2025-06-29T17:48:18.188Z
Learning: In the picojson-rs project, the `use tokenizer as ujson;` alias in lib.rs is a transitionary and fully internal private alias used during crate reorganization. Examples and external code no longer depend on this alias, making the private visibility appropriate.
🧬 Code Graph Analysis (3)
picojson/src/shared.rs (2)
picojson/src/slice_parser.rs (1)
  • next_event (449-451)
picojson/src/stream_parser.rs (1)
  • next_event (599-601)
picojson/src/slice_parser.rs (2)
picojson/src/stream_parser.rs (2)
  • next_event_impl (127-316)
  • next_event (599-601)
picojson/src/shared.rs (1)
  • next_event (117-117)
picojson/src/stream_parser.rs (2)
picojson/src/slice_parser.rs (2)
  • next_event_impl (260-445)
  • next_event (449-451)
picojson/src/shared.rs (2)
  • bytes_to_utf8_str (220-222)
  • next_event (117-117)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: AVR Panic Prevention
  • GitHub Check: Run AVR Test Suites
  • GitHub Check: AVR Panic Prevention
  • GitHub Check: Run AVR Test Suites
🔇 Additional comments (17)
avr_demo/examples/test_serde.rs (3)

9-21: LGTM: Well-implemented conditional compilation for ufmt feature.

The conditional import and fallback stub macro correctly handle cases where ufmt is not available. The stub macro returns the appropriate type signature Ok::<(), core::convert::Infallible>() that matches the expected uwriteln! return type.


32-37: LGTM: Proper conditional serial initialization.

Serial interface initialization is correctly guarded by the ufmt feature flag, preventing unnecessary resource allocation when formatting is disabled.


50-50: LGTM: Enhanced debug output.

The addition of status field printing provides better debugging information for JSON parsing verification.

picojson/src/number_parser.rs (1)

36-36: LGTM: Explicit lifetime annotations added to fix nightly warnings.

The return type now includes explicit lifetime parameters Event<'_, '_> which addresses nightly Rust compiler warnings about lifetime elision. This change maintains the same functionality while improving type clarity.

picojson/src/copy_on_escape.rs (1)

155-155: LGTM: Consistent lifetime annotation for String return type.

The explicit lifetime parameters String<'_, '_> align with the broader effort to fix nightly compiler warnings about lifetime elision. This change maintains API compatibility while improving type precision.

picojson/src/shared.rs (2)

109-109: LGTM: Updated trait method signature with explicit lifetimes.

The next() method now returns Event<'_, '_> with explicit lifetime parameters, ensuring consistency with the broader lifetime annotation effort across the codebase.


117-117: LGTM: Consistent trait signature for next_event method.

The explicit lifetime parameters in the return type ensure that implementers of this trait (like SliceParser and StreamParser shown in the relevant code snippets) maintain proper borrowing semantics.

avr_demo/examples/test_picojson.rs (5)

12-21: LGTM: Consistent conditional compilation pattern.

The conditional import and stub macro implementation matches the pattern used in test_serde.rs, providing proper fallback behavior when ufmt is not available.


67-69: LGTM: Safe buffer access replaces unsafe indexing.

Using get_mut() instead of direct slice indexing prevents potential panics if the buffer is too small, improving the robustness of the code.


90-96: LGTM: Proper error handling for string extraction.

The safe string extraction using get() and proper UTF-8 validation with a sensible fallback to empty string is much safer than the previous approach that could panic.


107-112: LGTM: Conditional serial initialization.

Serial interface initialization is properly guarded by the ufmt feature flag, consistent with the pattern used in test_serde.rs.


125-125: LGTM: Enhanced debug output for status field.

The additional debug print provides better visibility into the parsed JSON structure for testing and verification purposes.

picojson/src/slice_parser.rs (3)

175-188: Lifetime-annotated results look correct

All helper methods now return Result<Event<'_, '_>, ParseError> (or Option<Event<'_, '_>>).
This aligns with the new PullParser trait signature and keeps borrowing constraints explicit. No other changes required.


260-260: Signature refreshed – no issues

next_event_impl now advertises the explicit lifetimes. Implementation already satisfied the borrow checker via elision; this is purely syntactic and fine.


449-450: Trait method matches updated PullParser contract

The forwarding implementation compiles unchanged. ✅

picojson/src/stream_parser.rs (2)

323-327: Return-type updates are mechanically correct

All extraction helpers now propagate explicit lifetimes; implementation logic untouched. No regressions spotted.

Also applies to: 329-341, 345-349, 352-362, 365-377, 381-385, 388-398, 405-413


598-601: Forwarding impl remains correct

next_event simply delegates; lifetimes now explicit and consistent with the trait.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
avr_demo/run_suite.py (1)

33-35: Fix formatting: Add missing whitespace after commas.

The Python style guide (PEP 8) requires spaces after commas in lists.

-    ("picojson-tiny", "test_picojson", ["pico-tiny","ufmt"]),
-    ("picojson-small", "test_picojson", ["pico-small","ufmt"]),
-    ("picojson-huge", "test_picojson", ["pico-huge","ufmt"]),
+    ("picojson-tiny", "test_picojson", ["pico-tiny", "ufmt"]),
+    ("picojson-small", "test_picojson", ["pico-small", "ufmt"]),
+    ("picojson-huge", "test_picojson", ["pico-huge", "ufmt"]),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bcb112d and 5ba91a3.

📒 Files selected for processing (1)
  • avr_demo/run_suite.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: kaidokert
PR: kaidokert/picojson-rs#5
File: picojson/src/lib.rs:0-0
Timestamp: 2025-06-29T17:48:18.188Z
Learning: In the picojson-rs project, the `use tokenizer as ujson;` alias in lib.rs is a transitionary and fully internal private alias used during crate reorganization. Examples and external code no longer depend on this alias, making the private visibility appropriate.
🪛 Flake8 (7.2.0)
avr_demo/run_suite.py

[error] 33-33: missing whitespace after ','

(E231)


[error] 34-34: missing whitespace after ','

(E231)


[error] 35-35: missing whitespace after ','

(E231)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: AVR Panic Prevention
  • GitHub Check: Run AVR Test Suites
  • GitHub Check: Run AVR Test Suites
  • GitHub Check: AVR Panic Prevention
🔇 Additional comments (1)
avr_demo/run_suite.py (1)

32-35: Good alignment with conditional compilation changes.

The addition of "ufmt" feature to all test configurations properly supports the conditional compilation changes mentioned in the PR objectives. This ensures consistent feature availability across all demo configurations.

@kaidokert
kaidokert merged commit f0c0a71 into main Jul 3, 2025
@kaidokert
kaidokert deleted the lifetime_cleanup branch July 3, 2025 23:15
@coderabbitai coderabbitai Bot mentioned this pull request Apr 15, 2026
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.

1 participant