Skip to content

Commit c6ab1b1

Browse files
authored
Derive Default for enums (#2035)
The feature is stable since Rust 1.62.
1 parent 8a76ab7 commit c6ab1b1

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

elliptic-curve/src/dev.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,13 @@ impl IsHigh for Scalar {
447447
}
448448

449449
/// Example affine point type
450-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
450+
#[derive(Clone, Copy, Default, Debug, Eq, PartialEq)]
451451
pub enum AffinePoint {
452452
/// Result of fixed-based scalar multiplication.
453453
FixedBaseOutput(Scalar),
454454

455455
/// Identity.
456+
#[default]
456457
Identity,
457458

458459
/// Base point.
@@ -506,12 +507,6 @@ impl ConditionallySelectable for AffinePoint {
506507
}
507508
}
508509

509-
impl Default for AffinePoint {
510-
fn default() -> Self {
511-
Self::Identity
512-
}
513-
}
514-
515510
impl DefaultIsZeroes for AffinePoint {}
516511

517512
impl From<NonIdentity<AffinePoint>> for AffinePoint {
@@ -569,12 +564,13 @@ impl TryFrom<AffinePoint> for NonIdentity<AffinePoint> {
569564
}
570565

571566
/// Example projective point type
572-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
567+
#[derive(Clone, Copy, Default, Debug, Eq, PartialEq)]
573568
pub enum ProjectivePoint {
574569
/// Result of fixed-based scalar multiplication
575570
FixedBaseOutput(Scalar),
576571

577572
/// Is this point the identity point?
573+
#[default]
578574
Identity,
579575

580576
/// Is this point the generator point?
@@ -620,12 +616,6 @@ impl ConditionallySelectable for ProjectivePoint {
620616
}
621617
}
622618

623-
impl Default for ProjectivePoint {
624-
fn default() -> Self {
625-
Self::Identity
626-
}
627-
}
628-
629619
impl DefaultIsZeroes for ProjectivePoint {}
630620

631621
impl From<AffinePoint> for ProjectivePoint {

password-hash/src/encoding.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use base64ct::{
66
};
77

88
/// Base64 encoding variants.
9-
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
9+
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, PartialOrd, Ord)]
1010
#[non_exhaustive]
1111
pub enum Encoding {
1212
/// "B64" encoding: standard Base64 without padding.
@@ -16,6 +16,7 @@ pub enum Encoding {
1616
/// 0x41-0x5a, 0x61-0x7a, 0x30-0x39, 0x2b, 0x2f
1717
/// ```
1818
/// <https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md#b64>
19+
#[default]
1920
B64,
2021

2122
/// bcrypt encoding.
@@ -47,12 +48,6 @@ pub enum Encoding {
4748
ShaCrypt,
4849
}
4950

50-
impl Default for Encoding {
51-
fn default() -> Self {
52-
Self::B64
53-
}
54-
}
55-
5651
impl Encoding {
5752
/// Decode a Base64 string into the provided destination buffer.
5853
pub fn decode(self, src: impl AsRef<[u8]>, dst: &mut [u8]) -> Result<&[u8], B64Error> {

0 commit comments

Comments
 (0)