radicle: implement std::error::Error for AnnouncerError
This commit is contained in:
parent
e965d9a2c9
commit
c30298fb8a
|
|
@ -1,8 +1,7 @@
|
||||||
use std::{
|
use std::collections::{BTreeMap, BTreeSet};
|
||||||
collections::{BTreeMap, BTreeSet},
|
use std::fmt;
|
||||||
ops::ControlFlow,
|
use std::ops::ControlFlow;
|
||||||
time,
|
use std::time;
|
||||||
};
|
|
||||||
|
|
||||||
use crate::node::NodeId;
|
use crate::node::NodeId;
|
||||||
|
|
||||||
|
|
@ -394,6 +393,23 @@ pub enum AnnouncerError {
|
||||||
Target(TargetError),
|
Target(TargetError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for AnnouncerError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
AnnouncerError::AlreadySynced(AlreadySynced { preferred, synced }) => write!(
|
||||||
|
f,
|
||||||
|
"already synchronized with {synced} nodes ({preferred} preferred nodes)"
|
||||||
|
),
|
||||||
|
AnnouncerError::NoSeeds => {
|
||||||
|
f.write_str("no more nodes are available for synchronizing with")
|
||||||
|
}
|
||||||
|
AnnouncerError::Target(target_error) => target_error.fmt(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for AnnouncerError {}
|
||||||
|
|
||||||
impl From<AlreadySynced> for AnnouncerError {
|
impl From<AlreadySynced> for AnnouncerError {
|
||||||
fn from(value: AlreadySynced) -> Self {
|
fn from(value: AlreadySynced) -> Self {
|
||||||
Self::AlreadySynced(value)
|
Self::AlreadySynced(value)
|
||||||
|
|
@ -402,7 +418,11 @@ impl From<AlreadySynced> for AnnouncerError {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct AlreadySynced {
|
pub struct AlreadySynced {
|
||||||
|
/// The number of preferred nodes that are synchronized.
|
||||||
preferred: usize,
|
preferred: usize,
|
||||||
|
/// Total number nodes that are synchronized.
|
||||||
|
///
|
||||||
|
/// Note that this includes [`AlreadySynced::preferred`].
|
||||||
synced: usize,
|
synced: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue