Skip to main content

FieldValue

Enum FieldValue 

Source
pub enum FieldValue<'a> {
    Null,
    Text(&'a str),
}
Expand description

The value of one field of one item.

TLCP distinguishes null from the empty string, and so does this type: # on the wire produces FieldValue::Null and $ produces FieldValue::Text wrapping "" [docs/spec/04-notifications.md §2.2]. They are not interchangeable. A quote adapter that has no bid to report sends #; one whose status line is deliberately blank sends $.

§Examples

An ItemUpdate is obtained from a live subscription, so the example is written as the function you would pass one to — which compiles, and so keeps saying something true:

use lightstreamer_rs::{FieldValue, ItemUpdate};

fn report_bid(update: &ItemUpdate) {
    match update.field_by_name("bid") {
        Some(FieldValue::Text(bid)) => println!("bid is {bid}"),
        Some(FieldValue::Null) => println!("there is no bid"),
        None => println!("this subscription has no `bid` field"),
    }
}

The three arms are the three answers, and they are not interchangeable: Text("") is a fourth thing again — a value that happens to be empty. Use is_empty_text to ask.

Variants§

§

Null

The field has no value — the # marker [docs/spec/04-notifications.md §2.2].

Also what a field reads as before any update has ever set it, which is only observable between the subscription being activated and its first U: the first update of a subscription carries a token for every field [docs/spec/04-notifications.md §2.3].

§

Text(&'a str)

The field holds this text, which may be the empty string — the $ marker sets it to exactly that [docs/spec/04-notifications.md §2.2].

Implementations§

Source§

impl<'a> FieldValue<'a>

Source

pub const fn is_null(self) -> bool

Whether the field is null, i.e. has no value at all.

A field holding the empty string is not null.

Source

pub fn is_empty_text(self) -> bool

Whether the field holds the empty string.

A null field is not empty text: it has no text.

Source

pub const fn text(self) -> Option<&'a str>

The text, or None if the field is null.

Collapsing the distinction is a deliberate act here, which is the point: text() reads as “I am choosing to treat null as absent”, whereas an accessor that returned &str directly would make the same choice silently.

Source

pub fn text_or(self, default: &'a str) -> &'a str

The text, substituting default if the field is null.

This is how a field value is rendered for a human: Display is deliberately not implemented, because every rendering of a null has to choose a spelling and no choice is safe to make on the caller’s behalf — the empty string collapses null into $, and any placeholder is a string a field could legitimately hold. Naming the substitute at the call site is a one-word cost and it keeps println!("{}", value.text_or("(null)")) honest.

Trait Implementations§

Source§

impl<'a> Clone for FieldValue<'a>

Source§

fn clone(&self) -> FieldValue<'a>

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<'a> Copy for FieldValue<'a>

Source§

impl<'a> Debug for FieldValue<'a>

Source§

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

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

impl<'a> Eq for FieldValue<'a>

Source§

impl<'a> Hash for FieldValue<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for FieldValue<'a>

Source§

fn eq(&self, other: &FieldValue<'a>) -> bool

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

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

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for FieldValue<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for FieldValue<'a>

§

impl<'a> RefUnwindSafe for FieldValue<'a>

§

impl<'a> Send for FieldValue<'a>

§

impl<'a> Sync for FieldValue<'a>

§

impl<'a> Unpin for FieldValue<'a>

§

impl<'a> UnsafeUnpin for FieldValue<'a>

§

impl<'a> UnwindSafe for FieldValue<'a>

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