[][src]Struct ichen_openprotocol::MessageOptions

pub struct MessageOptions<'a> {
    pub id: Option<&'a str>,
    pub sequence: u64,
    pub priority: i32,
}

Common options of an Open Protocol message.

Fields

id: Option<&'a str>

Unique ID (if any) of the message for tracking and storage retrieval purposes.

The iChen Server may tag certain messages with a unique tracking key that can be used to retrieve the message from persistent storage later.

sequence: u64

Ever-increasing message sequence number.

This number is usually auto-incremented with each message created, starting from 1.

priority: i32

Priority of the message, smaller number is higher priority. Default = 0.

Methods

impl<'a> MessageOptions<'a>[src]

pub fn new() -> Self[src]

Create a MessageOptions with default values (for example, the sequence field auto-increments).

Examples

let opt1 = MessageOptions::new();
assert_eq!(1, opt1.sequence);
assert_eq!(0, opt1.priority);

let opt2 = MessageOptions::new();
assert_eq!(2, opt2.sequence);       // `sequence` auto-increments.
assert_eq!(0, opt2.priority);

pub fn new_with_priority(priority: i32) -> Self[src]

Create a MessageOptions with a particular priority but otherwise default values (for example, the sequence field auto-increments).

Examples

let opt1 = MessageOptions::new_with_priority(100);
assert_eq!(1, opt1.sequence);
assert_eq!(100, opt1.priority);

let opt2 = MessageOptions::new_with_priority(-42);
assert_eq!(2, opt2.sequence);       // `sequence` auto-increments.
assert_eq!(-42, opt2.priority);

pub fn validate(&self) -> Result<'static, ()>[src]

Validate the data structure.

Errors

Returns Err(OpenProtocolError::EmptyField) if the id field is set to an empty string or is all whitespace.

Examples

let opt1 = MessageOptions { id: Some(""), ..Default::default() };
assert_eq!(r#"Err(EmptyField("id"))"#, format!("{:?}", opt1.validate()));

Trait Implementations

impl<'a> Clone for MessageOptions<'a>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'_> Default for MessageOptions<'_>[src]

fn default() -> Self[src]

Default value for MessageOptions.

The sequence field is auto-incrementing.

Examples

let opt1: MessageOptions = Default::default();
assert_eq!(1, opt1.sequence);
assert_eq!(0, opt1.priority);

let opt2: MessageOptions = Default::default();
assert_eq!(2, opt2.sequence);       // `sequence` auto-increments.
assert_eq!(0, opt2.priority);

impl<'a> PartialEq<MessageOptions<'a>> for MessageOptions<'a>[src]

impl<'a> Debug for MessageOptions<'a>[src]

impl<'a> Serialize for MessageOptions<'a>[src]

impl<'de: 'a, 'a> Deserialize<'de> for MessageOptions<'a>[src]

Auto Trait Implementations

impl<'a> Sync for MessageOptions<'a>

impl<'a> Send for MessageOptions<'a>

impl<'a> Unpin for MessageOptions<'a>

impl<'a> RefUnwindSafe for MessageOptions<'a>

impl<'a> UnwindSafe for MessageOptions<'a>

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]