Skip to content

Commit 8603719

Browse files
committed
Merge #578: Implement Debug trait for Scalar type
8ed8cac Implement `Debug` trait for `Scalar` type. (Arik Sosman) Pull request description: Currently, `Scalar` types do not implement the `Debug` trait, whereas most other types in the library do. Besides that being an upstream requirement for us, I believe it would also be quite useful for users of that type. Also implements the `Index` traits for `Scalar`. ACKs for top commit: apoelstra: ACK 8ed8cac Tree-SHA512: f254859144850e40badf6ace2b2a1b231e5ed224ec60861586cd5f2042167d89c759dc16a1075702bce90d810ac60db924ea8cb20d82099a42fddb2718da12db
2 parents 65eb166 + 8ed8cac commit 8603719

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/scalar.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! provides the `Scalar` type and related.
77
//!
88
9-
use core::fmt;
9+
use core::{fmt, ops};
1010

1111
use crate::constants;
1212

@@ -23,6 +23,7 @@ use crate::constants;
2323
#[allow(missing_debug_implementations)]
2424
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
2525
pub struct Scalar([u8; 32]);
26+
impl_pretty_debug!(Scalar);
2627

2728
const MAX_RAW: [u8; 32] = [
2829
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
@@ -107,6 +108,16 @@ impl Scalar {
107108
}
108109
}
109110

111+
impl<I> ops::Index<I> for Scalar
112+
where
113+
[u8]: ops::Index<I>,
114+
{
115+
type Output = <[u8] as ops::Index<I>>::Output;
116+
117+
#[inline]
118+
fn index(&self, index: I) -> &Self::Output { &self.0[index] }
119+
}
120+
110121
impl From<crate::SecretKey> for Scalar {
111122
fn from(value: crate::SecretKey) -> Self { Scalar(value.secret_bytes()) }
112123
}

0 commit comments

Comments
 (0)