-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(katana): Cairo short string #2991
Conversation
Ohayo sensei! WalkthroughThis pull request introduces a new dependency to the Changes
Sequence Diagram(s)sequenceDiagram
participant User as Sensei
participant SS as ShortString
participant HStr as heapless::String<31>
participant Felt as Felt
User->>SS: Call from_str(input)
SS->>HStr: Initialize internal string storage
HStr-->>SS: Return constructed string
SS-->>User: Return ShortString instance
User->>SS: Request conversion into Felt (via Into/Fn call)
SS->>Felt: Convert internal representation
Felt-->>SS: Return Felt result
SS-->>User: Return conversion output
Tip 🌐 Web search-backed reviews and chat
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
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)
crates/katana/primitives/src/cairo.rs (1)
26-34
: Consider exposing push/push_str as public for flexibility.Currently,
push
andpush_str
are private. If there's a usage scenario where partial or incremental building of aShortString
beyond constructor usage is needed, having public methods could be helpful. Otherwise, if they're private by design, this is fine.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Cargo.lock
is excluded by!**/*.lock
📒 Files selected for processing (3)
crates/katana/primitives/Cargo.toml
(1 hunks)crates/katana/primitives/src/cairo.rs
(1 hunks)crates/katana/primitives/src/lib.rs
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- crates/katana/primitives/src/lib.rs
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: fmt
🔇 Additional comments (7)
crates/katana/primitives/src/cairo.rs (6)
1-2
: Ohayo sensei! Looks good so far.The
use crate::Felt;
import is correct and aligned with the usage throughout the file. No concerns.
3-7
: Struct definition is concise and tidy, sensei!Defining
ShortString
as a tuple struct withheapless::String<31>
cleanly encapsulates functionality. This minimal design also helps keep memory usage predictable.
57-63
: Error definitions are well-structured, sensei!Enumerating distinct cases like
StringTooLong
andInvalidAsciiString
ensures clarity in error reporting and debugging. Keep it up.
65-82
: Input validation is thorough.The
is_ascii()
check and length constraint effectively shield against invalid short strings. The directpush_str(...)
call with a pre-checked length is fine. Watch out for any future expansions that might alter length constraints.
112-143
: Clever handling of leading zeros and null terminators, sensei!Your conversion logic systematically guards against malformed data. The design of rejecting null bytes after starting the string is consistent with a contiguous short string approach in Cairo. This is a well-thought-out solution.
175-304
: Test coverage is commendable, sensei!The wide range of unit tests (normal cases, edge cases, and error conditions) inspires confidence in correctness. The
rstest
usage for repeated cases is especially neat. No further changes needed.crates/katana/primitives/Cargo.toml (1)
16-16
: Ohayo sensei, new dependency is good to go!Adding
heapless = { version = "0.8.0", features = [ "serde" ] }
is essential for the short-string functionality. This version and feature set is well-aligned with your usage.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2991 +/- ##
==========================================
+ Coverage 56.97% 57.05% +0.08%
==========================================
Files 426 427 +1
Lines 56376 56536 +160
==========================================
+ Hits 32119 32257 +138
- Misses 24257 24279 +22 ☔ View full report in Codecov by Sentry. |
Define Cairo short string type https://book.cairo-lang.org/ch02-02-data-types.html#short-strings
Summary by CodeRabbit