pub struct MessageOptions<'a> { /* private fields */ }
Expand description
Common options of an Open Protocol message.
Implementations§
Source§impl<'a> MessageOptions<'a>
impl<'a> MessageOptions<'a>
Sourcepub fn id(&self) -> Option<&str>
pub fn id(&self) -> Option<&str>
Get the message ID, if any.
§Examples
let mut opt = MessageOptions::new();
opt.set_id("hello")?;
assert_eq!(Some("hello"), opt.id());
opt.clear_id();
assert_eq!(None, opt.id());
Sourcepub fn sequence(&self) -> u64
pub fn sequence(&self) -> u64
§Examples
let opt1 = MessageOptions::new();
assert_eq!(1, opt1.sequence());
let opt2 = MessageOptions::new();
assert_eq!(2, opt2.sequence()); // `sequence` auto-increments.
Sourcepub fn priority(&self) -> i32
pub fn priority(&self) -> i32
Get the message priority.
§Examples
let opt1 = MessageOptions::new_with_priority(100);
assert_eq!(100, opt1.priority());
let opt2 = MessageOptions::new_with_priority(-42);
assert_eq!(-42, opt2.priority());
Sourcepub fn set_id(&mut self, id: &'a str) -> Result<(), String>
pub fn set_id(&mut self, id: &'a str) -> Result<(), String>
Set the message ID.
§Errors
Returns Err(String)
if the ID string is empty or all-whitespace.
§Error Examples
let mut opt = MessageOptions::new();
assert_eq!(Err("invalid value: a non-empty, non-whitespace, all-ASCII string required".into()), opt.set_id(""));
§Examples
let mut opt = MessageOptions::new();
opt.set_id("hello")?;
assert_eq!(Some("hello"), opt.id());
opt.clear_id();
assert_eq!(None, opt.id());
Sourcepub fn clear_id(&mut self)
pub fn clear_id(&mut self)
Set the message ID to None
.
§Examples
let mut opt = MessageOptions::new();
opt.set_id("hello")?;
assert_eq!(Some("hello"), opt.id());
opt.clear_id();
assert_eq!(None, opt.id());
Sourcepub fn new() -> Self
pub fn new() -> Self
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());
Sourcepub fn new_with_priority(priority: i32) -> Self
pub fn new_with_priority(priority: i32) -> Self
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());
Trait Implementations§
Source§impl<'a> Clone for MessageOptions<'a>
impl<'a> Clone for MessageOptions<'a>
Source§fn clone(&self) -> MessageOptions<'a>
fn clone(&self) -> MessageOptions<'a>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<'a> Debug for MessageOptions<'a>
impl<'a> Debug for MessageOptions<'a>
Source§impl Default for MessageOptions<'_>
impl Default for MessageOptions<'_>
Source§fn default() -> Self
fn default() -> Self
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());
Source§impl<'de: 'a, 'a> Deserialize<'de> for MessageOptions<'a>
impl<'de: 'a, 'a> Deserialize<'de> for MessageOptions<'a>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<'a> Hash for MessageOptions<'a>
impl<'a> Hash for MessageOptions<'a>
Auto Trait Implementations§
impl<'a> Freeze for MessageOptions<'a>
impl<'a> RefUnwindSafe for MessageOptions<'a>
impl<'a> Send for MessageOptions<'a>
impl<'a> Sync for MessageOptions<'a>
impl<'a> Unpin for MessageOptions<'a>
impl<'a> UnwindSafe for MessageOptions<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more