use std::collections::HashMap;
use std::ops::{Deref, DerefMut};
use nostr::event::EventId;
use nostr::message::SubscriptionId;
use nostr::types::RelayUrl;
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Output<T, S = (), F = String> {
pub value: T,
pub success: HashMap<RelayUrl, S>,
pub failed: HashMap<RelayUrl, F>,
}
impl<T, S, F> Deref for Output<T, S, F> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.value
}
}
impl<T, S, F> DerefMut for Output<T, S, F> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.value
}
}
impl<T, S, F> Output<T, S, F> {
#[inline]
#[must_use]
pub fn new(value: T) -> Self {
Self {
value,
success: HashMap::new(),
failed: HashMap::new(),
}
}
}
impl<S, F> Output<EventId, S, F> {
#[inline]
#[must_use]
pub fn id(&self) -> &EventId {
self.deref()
}
}
impl<S, F> Output<SubscriptionId, S, F> {
#[inline]
#[must_use]
pub fn id(&self) -> &SubscriptionId {
self.deref()
}
}