From ceb970c211fd5d0b4556221e2d57c4e1944d435a Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 5 Dec 2023 19:03:43 +0000 Subject: [PATCH] Fix clippy lint --- Cargo.toml | 4 ++++ src/lib.rs | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3bc7e2f..e4cc027 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,7 @@ subtle = "2.2.3" [dev-dependencies] assert_matches = "1.5" + +[features] +default = ["std"] +std = [] diff --git a/src/lib.rs b/src/lib.rs index 8253912..7cf2626 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,9 @@ #![deny(unsafe_code)] #![deny(rustdoc::broken_intra_doc_links)] +#[cfg(feature = "std")] +extern crate std; + use memuse::{self, DynamicUsage}; use subtle::{Choice, ConditionallySelectable}; @@ -138,7 +141,7 @@ impl DiversifierIndex { } /// Increments this index, failing on overflow. - pub fn increment(&mut self) -> Result<(), ()> { + pub fn increment(&mut self) -> Result<(), DiversifierIndexOverflowError> { for k in 0..11 { self.0[k] = self.0[k].wrapping_add(1); if self.0[k] != 0 { @@ -147,10 +150,23 @@ impl DiversifierIndex { } } // Overflow - Err(()) + Err(DiversifierIndexOverflowError) } } +/// The error type returned when a [`DiversifierIndex`] increment fails. +#[derive(Clone, Copy, Debug)] +pub struct DiversifierIndexOverflowError; + +impl core::fmt::Display for DiversifierIndexOverflowError { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "DiversifierIndex increment overflowed") + } +} + +#[cfg(feature = "std")] +impl std::error::Error for DiversifierIndexOverflowError {} + /// The scope of a viewing key or address. /// /// A "scope" narrows the visibility or usage to a level below "full".