use {
crate::{DatastarEvent, consts},
core::time::Duration,
};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct RemoveSignals {
pub id: Option<String>,
pub retry: Duration,
pub paths: Vec<String>,
}
impl RemoveSignals {
pub fn new(paths: impl IntoIterator<Item = impl Into<String>>) -> Self {
Self {
id: None,
retry: Duration::from_millis(consts::DEFAULT_SSE_RETRY_DURATION),
paths: paths.into_iter().map(Into::into).collect(),
}
}
pub fn id(mut self, id: impl Into<String>) -> Self {
self.id = Some(id.into());
self
}
pub fn retry(mut self, retry: Duration) -> Self {
self.retry = retry;
self
}
#[inline]
pub fn into_event(self) -> DatastarEvent {
self.into()
}
}
impl From<RemoveSignals> for DatastarEvent {
fn from(val: RemoveSignals) -> Self {
let mut data: Vec<String> = Vec::new();
for line in &val.paths {
data.push(format!("{} {}", consts::PATHS_DATALINE_LITERAL, line));
}
Self {
event: consts::EventType::RemoveSignals,
id: val.id,
retry: val.retry,
data,
}
}
}