Skip to content

feat: support no_std#74

Open
hsqStephenZhang wants to merge 1 commit intomozillazg:masterfrom
hsqStephenZhang:feat/no_std
Open

feat: support no_std#74
hsqStephenZhang wants to merge 1 commit intomozillazg:masterfrom
hsqStephenZhang:feat/no_std

Conversation

@hsqStephenZhang
Copy link
Copy Markdown

@hsqStephenZhang hsqStephenZhang commented Apr 2, 2026

Summary by CodeRabbit

  • Refactor
    • Library now supports no_std environments, enabling use in embedded systems and resource-constrained platforms. Full API compatibility maintained with improved portability across diverse deployment targets.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

📝 Walkthrough

Walkthrough

The crate is being migrated to no_std mode by replacing standard library dependencies with core equivalents and introducing alloc support. Imports are systematically updated across files, hashbrown::HashSet replaces std::collections::HashSet, and the to_pinyin_vec function signature is adjusted for the new allocation model.

Changes

Cohort / File(s) Summary
Crate root configuration
Cargo.toml
Added hashbrown v0.16.1 with alloc feature to the special_pinyin test target dependencies.
Library initialization
src/lib.rs
Switched crate to #![no_std] mode, replaced std::convert::TryFrom with core::convert::TryFrom, added extern crate alloc, and updated to_pinyin_vec return type to alloc::vec::Vec<&'static str>.
Module imports
src/pinyin.rs, src/pinyin_multi.rs
Replaced std::str::Chars import with core::str::Chars for character iteration; added use alloc::vec::Vec; in test module of pinyin_multi.rs.
Compatibility layer
src/compat.rs
Replaced std::collections::HashSet with hashbrown::HashSet in deprecated pinyin function; updated imports to use alloc types (alloc::string::{String, ToString} and alloc::vec::Vec).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • mozillazg

Poem

🐰 No standard library, yet we still hop so fast,
Core and alloc dance where the standard library passed,
Hashbrown's hash sets shimmer in embedded dreams,
Our pinyin sings lighter, or so it seems!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: support no_std' directly reflects the main objective of the pull request, which is to migrate the crate to no_std mode as evidenced by switching to #![no_std], updating imports to use core and alloc types, and adding hashbrown dependency.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
Cargo.toml (1)

65-66: Scope hashbrown to compat to keep non-compat builds lean.

hashbrown is used only in src/compat.rs:90, and src/lib.rs already gates that module behind feature = "compat". Making this dependency optional and enabling it via compat avoids pulling it in for builds that don't use compatibility APIs.

Proposed manifest wiring
 [features]
 compat = [
     "plain",
     "with_tone",
     "with_tone_num",
     "heteronym",
+    "dep:hashbrown",
 ]

 [dependencies]
-hashbrown = { version = "0.16.1", features = ["alloc"] }
+hashbrown = { version = "0.16.1", features = ["alloc"], optional = true }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Cargo.toml` around lines 65 - 66, The Cargo.toml currently always pulls in
hashbrown; make the dependency optional and tied to the "compat" feature so
non-compat builds stay lean: change the hashbrown entry to be optional and add
it to the "compat" feature (so it is enabled when the "compat" feature is
enabled), because hashbrown is only used in src/compat.rs (around line
referencing src/compat.rs:90) and that module is already gated by the "compat"
feature in src/lib.rs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@Cargo.toml`:
- Around line 65-66: The Cargo.toml currently always pulls in hashbrown; make
the dependency optional and tied to the "compat" feature so non-compat builds
stay lean: change the hashbrown entry to be optional and add it to the "compat"
feature (so it is enabled when the "compat" feature is enabled), because
hashbrown is only used in src/compat.rs (around line referencing
src/compat.rs:90) and that module is already gated by the "compat" feature in
src/lib.rs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4fcaad63-4c30-4a6d-979e-2c4dfa84e1e3

📥 Commits

Reviewing files that changed from the base of the PR and between 76fc7d3 and 10f5484.

📒 Files selected for processing (5)
  • Cargo.toml
  • src/compat.rs
  • src/lib.rs
  • src/pinyin.rs
  • src/pinyin_multi.rs

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