use live_data::{
FilterExpr, FormatPreference, Sampling, SubscriptionDescriptor, TransportPreference,
TransportTag,
};
#[derive(Debug, Clone)]
pub struct SubscriptionBuilder {
inner: SubscriptionDescriptor,
}
impl SubscriptionBuilder {
pub fn new(feed: impl Into<String>) -> Self {
Self { inner: SubscriptionDescriptor::new(feed) }
}
pub fn columns<I, S>(mut self, cols: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.inner.columns = Some(cols.into_iter().map(Into::into).collect());
self
}
pub fn filter(mut self, f: FilterExpr) -> Self {
self.inner.filter = f;
self
}
pub fn sampling(mut self, s: Sampling) -> Self {
self.inner.sampling = Some(s);
self
}
pub fn transport_pref(mut self, p: TransportPreference) -> Self {
self.inner.transport_pref = p;
self
}
pub fn prefer_transport(mut self, t: TransportTag) -> Self {
self.inner.transport_pref.0.push(t);
self
}
pub fn format(mut self, f: FormatPreference) -> Self {
self.inner.format_pref = Some(f);
self
}
pub fn build(self) -> SubscriptionDescriptor {
self.inner
}
}
impl From<SubscriptionBuilder> for SubscriptionDescriptor {
fn from(b: SubscriptionBuilder) -> Self {
b.build()
}
}