Skip to content

Commit 8ed8cac

Browse files
committed
Implement Debug trait for Scalar type.
1 parent 65eb166 commit 8ed8cac

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)