Skip to main content

Subscription

Struct Subscription 

Source
pub struct Subscription { /* private fields */ }
Expand description

A request to subscribe to a set of items.

Build one, hand it to Client::subscribe, and consume the Updates stream you get back. The three values with no default — the mode, the items and the fields — are taken by Subscription::new; everything else is optional and defaults to letting the server decide.

§Not every combination is a subscription

The optional parameters are not independent of the mode: a snapshot length is admitted only in SubscriptionMode::Distinct, and a snapshot, a frequency cap and a buffer size are each meaningless in SubscriptionMode::Raw [docs/spec/03-requests.md §6.1]. The setters stay infallible so that they chain, and the whole combination is checked at once by Subscription::validate — which Client::subscribe calls before anything is sent, so an impossible subscription is a typed error at the call rather than a stream that never activates.

§Examples

use lightstreamer_rs::{FieldSchema, ItemGroup, Snapshot, Subscription, SubscriptionMode};

let subscription = Subscription::new(
    SubscriptionMode::Merge,
    ItemGroup::from_items(["item1", "item2"])?,
    FieldSchema::from_fields(["last_price", "time"])?,
)
.with_snapshot(Snapshot::On);

assert_eq!(subscription.mode(), SubscriptionMode::Merge);

Implementations§

Source§

impl Subscription

Source

pub fn new( mode: SubscriptionMode, items: ItemGroup, fields: FieldSchema, ) -> Self

A subscription to a set of items, for a set of fields, in a mode.

Source

pub fn with_data_adapter(self, name: impl Into<String>) -> Self

Names the Data Adapter within the session’s Adapter Set that provides these items.

Left unset, the server uses the Adapter Set’s default Data Adapter [docs/spec/03-requests.md §6.1].

Source

pub fn with_selector(self, name: impl Into<String>) -> Self

Passes a selector name to the Metadata Adapter, which uses it to filter the updates of every item in the subscription [docs/spec/03-requests.md §6.1].

What a selector name means is entirely up to the adapter.

Source

pub const fn with_snapshot(self, snapshot: Snapshot) -> Self

Asks for a snapshot before the live flow.

Source

pub fn with_max_frequency(self, frequency: MaxFrequency) -> Self

Caps how often the server sends updates for each item.

Source

pub const fn with_buffer_size(self, size: BufferSize) -> Self

Asks the server for a particular per-item buffer size.

Source

pub const fn mode(&self) -> SubscriptionMode

The mode this subscription was built with.

Source

pub const fn items(&self) -> &ItemGroup

The items this subscription covers.

Source

pub const fn fields(&self) -> &FieldSchema

The fields this subscription asks for.

Source

pub const fn snapshot(&self) -> Snapshot

Whether a snapshot was asked for.

Source

pub fn validate(&self) -> Result<(), ConfigError>

Checks that the mode admits every option this subscription carries.

Client::subscribe calls this first, so a caller never has to; it is public because checking a configuration before a client exists is sometimes what you want, and because the error is more useful at the line that built the subscription than at the line that sent it.

§Errors

The last four are refused rather than dropped. The server would accept the request and ignore the parameter [docs/spec/03-requests.md §6.1], which means a caller who asked for a cap would run without one and never be told — a silent difference between what was written and what is happening.

§Examples
use lightstreamer_rs::{
    ConfigError, FieldSchema, ItemGroup, Snapshot, Subscription, SubscriptionMode,
};

let raw = Subscription::new(
    SubscriptionMode::Raw,
    ItemGroup::from_items(["item1"])?,
    FieldSchema::from_fields(["last_price"])?,
)
.with_snapshot(Snapshot::On);

assert!(matches!(
    raw.validate(),
    Err(ConfigError::SnapshotNeedsAStatefulMode)
));

Trait Implementations§

Source§

impl Clone for Subscription

Source§

fn clone(&self) -> Subscription

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Subscription

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Subscription

Source§

impl PartialEq for Subscription

Source§

fn eq(&self, other: &Subscription) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Subscription

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more