use crate::ListenerError;
#[derive(Debug)]
#[must_use = "DispatchResult carries listener errors that will be silently dropped if ignored"]
pub struct DispatchResult {
listener_count: usize,
errors: Vec<ListenerError>,
blocked: bool,
}
impl DispatchResult {
pub(crate) fn new(listener_count: usize, errors: Vec<ListenerError>) -> Self {
Self {
listener_count,
errors,
blocked: false,
}
}
pub(crate) fn blocked() -> Self {
Self {
listener_count: 0,
errors: Vec::new(),
blocked: false,
}
.with_blocked()
}
fn with_blocked(mut self) -> Self {
self.blocked = true;
self
}
#[must_use]
pub fn is_blocked(&self) -> bool {
self.blocked
}
#[must_use]
pub fn listener_count(&self) -> usize {
self.listener_count
}
#[must_use]
pub fn success_count(&self) -> usize {
self.listener_count.saturating_sub(self.errors.len())
}
#[must_use]
pub fn error_count(&self) -> usize {
self.errors.len()
}
#[must_use]
pub fn errors(&self) -> &[ListenerError] {
&self.errors
}
#[must_use]
pub fn all_succeeded(&self) -> bool {
!self.blocked && self.errors.is_empty()
}
#[must_use]
pub fn has_errors(&self) -> bool {
!self.errors.is_empty()
}
}