1use live_data::{
4 FilterExpr, FormatPreference, Sampling, SubscriptionDescriptor, TransportPreference,
5 TransportTag,
6};
7
8#[derive(Debug, Clone)]
14pub struct SubscriptionBuilder {
15 inner: SubscriptionDescriptor,
16}
17
18impl SubscriptionBuilder {
19 pub fn new(feed: impl Into<String>) -> Self {
20 Self { inner: SubscriptionDescriptor::new(feed) }
21 }
22
23 pub fn columns<I, S>(mut self, cols: I) -> Self
26 where
27 I: IntoIterator<Item = S>,
28 S: Into<String>,
29 {
30 self.inner.columns = Some(cols.into_iter().map(Into::into).collect());
31 self
32 }
33
34 pub fn filter(mut self, f: FilterExpr) -> Self {
35 self.inner.filter = f;
36 self
37 }
38
39 pub fn sampling(mut self, s: Sampling) -> Self {
40 self.inner.sampling = Some(s);
41 self
42 }
43
44 pub fn transport_pref(mut self, p: TransportPreference) -> Self {
46 self.inner.transport_pref = p;
47 self
48 }
49
50 pub fn prefer_transport(mut self, t: TransportTag) -> Self {
53 self.inner.transport_pref.0.push(t);
54 self
55 }
56
57 pub fn format(mut self, f: FormatPreference) -> Self {
58 self.inner.format_pref = Some(f);
59 self
60 }
61
62 pub fn build(self) -> SubscriptionDescriptor {
63 self.inner
64 }
65}
66
67impl From<SubscriptionBuilder> for SubscriptionDescriptor {
68 fn from(b: SubscriptionBuilder) -> Self {
69 b.build()
70 }
71}