Skip to content
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(corelib): Impl fmt::debug for Range #6926

Merged
merged 2 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions corelib/src/ops/range.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ pub struct Range<T> {
pub end: T,
}

impl RangeDebug<T, impl TDebug: crate::fmt::Debug<T>> of crate::fmt::Debug<Range<T>> {
/// Formats a `Range` type, allowing to print `Range` instances for debugging purposes.
///
/// # Examples
///
/// ```
/// println!("{:?}", 1..5); // Result will be `1..5`
/// ```
fn fmt(self: @Range<T>, ref f: crate::fmt::Formatter) -> Result<(), crate::fmt::Error> {
self.start.fmt(ref f)?;
write!(f, "..")?;
self.end.fmt(ref f)?;
Result::Ok(())
}
}

/// Handles the range operator (`..`).
#[generate_trait]
pub impl RangeOpImpl<T> of RangeOp<T> {
Expand Down
1 change: 1 addition & 0 deletions corelib/src/test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod num_test;
mod option_test;
mod plugins_test;
mod print_test;
mod range_test;
mod result_test;
mod secp256k1_test;
mod secp256r1_test;
Expand Down
4 changes: 4 additions & 0 deletions corelib/src/test/range_test.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn test_range_format() {
assert!(format!("{:?}", 1..5) == "1..5");
}
Loading