[][src]Struct blather::Telegram

pub struct Telegram { /* fields omitted */ }

Representation of a Telegram buffer.

Implementations

impl Telegram[src]

pub fn new() -> Self[src]

Create a new telegram object, with an unset topic.

Note that a telegram object without a topic is invalid. set_topic must be called to set a topic to make the object valid.

pub fn new_topic(topic: &str) -> Result<Self, Error>[src]

Create a new telegram object with a topic.

pub fn clear(&mut self)[src]

Clear topic and internal parameters buffer.

pub fn get_params(&self) -> &Params[src]

Get a reference to the internal parameters object.

pub fn get_params_inner(&self) -> &HashMap<String, String>[src]

Get a reference the the parameter's internal HashMap.

Note: The inner representation of the Params object may change in the future.

pub fn set_topic(&mut self, topic: &str) -> Result<(), Error>[src]

Set topic for telegram.

Overwrites current topic is one has already been set.

pub fn get_topic(&self) -> Option<&str>[src]

Get a reference to the topic string, or None if topic is not been set.

pub fn add_param<T: ToString, U: ToString>(&mut self, key: T, value: U)[src]

Add a parameter to the telegram.

pub fn add_str<T: ToString, U: ToString>(&mut self, key: T, value: U)[src]

Add a string parameter to the telegram.

pub fn have_param(&self, key: &str) -> bool[src]

pub fn get_param<T: FromStr>(&self, key: &str) -> Result<T, Error>[src]

Get a string representation of a parameter.

pub fn get_str(&self, key: &str) -> Option<&str>[src]

Get a string representation of a parameter.

pub fn get_int<T: FromStr>(&self, key: &str) -> Result<T, Error>[src]

Get an integer representation of a parameter.

use blather::Telegram;
fn main() {
  let mut tg = Telegram::new();
  tg.add_param("Num", 7);
  assert_eq!(tg.get_int::<usize>("Num").unwrap(), 7);
}

Note: This function uses the FromStr trait so it technically isn't limited to integers. The method name is chosen to mimic a C++ library.

pub fn get_int_def<T: FromStr>(&self, key: &str, def: T) -> Result<T, Error>[src]

Try to get the parameter value of a key and interpret it as an integer. If the key does not exist then return a default value supplied by the caller.

use blather::Telegram;
fn main() {
  let mut tg = Telegram::new();
  tg.add_param("num", 11);
  assert_eq!(tg.get_int_def::<u32>("num", 5).unwrap(), 11);
  assert_eq!(tg.get_int_def::<u32>("nonexistent", 17).unwrap(), 17);
}

pub fn calc_buf_size(&self) -> usize[src]

Calculate the size of a serialized version of this Telegram object. If no topic has been set it is simply ignored. In the future this might change to something more dramatic, like a panic. Telegrams should always contain a topic when transmitted.

Each line is terminated by a newline character. The last line consists of a single newline character.

pub fn serialize(&self) -> Result<Vec<u8>, Error>[src]

pub fn into_params(self) -> Params[src]

Consume the Telegram buffer and return the internal parameters object.

Trait Implementations

impl Clone for Telegram[src]

impl Debug for Telegram[src]

impl Default for Telegram[src]

impl Display for Telegram[src]

impl From<HashMap<String, String, RandomState>> for Telegram[src]

impl From<Params> for Telegram[src]

impl From<String> for Telegram[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[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.