Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
CyonAlexRDX committed Aug 28, 2024
1 parent c9e465d commit 08783c6
Showing 1 changed file with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
use crate::prelude::*;

/// A neglected factor, with a reason.
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct AbstractNeglectedFactor<T> {
/// The reason why this factor was neglected.
pub reason: NeglectFactorReason,

/// The neglected factor
pub content: T,
}

impl<T> AbstractNeglectedFactor<T> {
pub fn new(reason: NeglectFactorReason, content: T) -> Self {
Self { reason, content }
}
}

impl<T: std::fmt::Debug> std::fmt::Debug for AbstractNeglectedFactor<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Neglected")
.field("reason", &self.reason)
.field("content", &self.content)

Check warning on line 23 in src/signing/petition_types/petition_factors_types/neglected_factor_instance.rs

View check run for this annotation

Codecov / codecov/patch

src/signing/petition_types/petition_factors_types/neglected_factor_instance.rs#L23

Added line #L23 was not covered by tests
.finish()
}
}

impl NeglectedFactorInstance {
/// Maps from `Neglected<HierarchicalDeterministicFactorInstance>`
/// to `Neglected<FactorSourceIDFromHash>`,
pub fn as_neglected_factor(&self) -> NeglectedFactor {
NeglectedFactor::new(self.reason, self.factor_source_id())
}
Expand Down Expand Up @@ -32,36 +59,25 @@ impl HasSampleValues for NeglectedFactorInstance {
}
}

/// ID to some neglected factor source, with the reason why it was neglected (skipped/failed)
pub type NeglectedFactor = AbstractNeglectedFactor<FactorSourceIDFromHash>;
pub type NeglectedFactors = AbstractNeglectedFactor<IndexSet<FactorSourceIDFromHash>>;
pub type NeglectedFactorInstance = AbstractNeglectedFactor<HierarchicalDeterministicFactorInstance>;

#[derive(Clone, PartialEq, Eq, Hash)]
pub struct AbstractNeglectedFactor<T> {
pub reason: NeglectFactorReason,
pub content: T,
}
impl<T> AbstractNeglectedFactor<T> {
pub fn new(reason: NeglectFactorReason, content: T) -> Self {
Self { reason, content }
}
}
/// IDs to some neglected factor source, with the reason why they were neglected (skipped/failed)
pub type NeglectedFactors = AbstractNeglectedFactor<IndexSet<FactorSourceIDFromHash>>;

impl<T: std::fmt::Debug> std::fmt::Debug for AbstractNeglectedFactor<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Neglected")
.field("reason", &self.reason)
.field("content", &self.content)
.finish()
}
}
/// A HierarchicalDeterministicFactorInstance which was rejected, with the reason why (skipped/failed)
pub type NeglectedFactorInstance = AbstractNeglectedFactor<HierarchicalDeterministicFactorInstance>;

/// Reason why some FactorSource was neglected, either explicitly skipped by the user
/// or implicitly neglected due to failure.
#[derive(Clone, Copy, PartialEq, Eq, Hash, derive_more::Debug, derive_more::Display)]
pub enum NeglectFactorReason {
/// A FactorSource got neglected since user explicitly skipped it.
#[display("User Skipped")]
#[debug("UserExplicitlySkipped")]
UserExplicitlySkipped,

/// A FactorSource got neglected implicitly due to failure
#[display("Failure")]
#[debug("Failure")]
Failure,
Expand Down

0 comments on commit 08783c6

Please sign in to comment.