Struct irc_rust::Message [−][src]
A simple irc message containing tags, prefix, command, parameters and a trailing parameter.
All types returned from getters of this type ([Prefix, Params, Tags]) are owned types. So they are tied to the Message instance they are retrieved from and don’t own their part of the message.
Parses its part lazily on method invokations.
Examples
Create a Message from a plain string.
use irc_rust::Message; let message = Message::from("@key1=value1;key2=value2 :name!user@host CMD param1 param2 :trailing"); assert_eq!(message.to_string(), "@key1=value1;key2=value2 :name!user@host CMD param1 param2 :trailing");
To build a message in a verbose and easy to read way you can use the Message::builder
method and the MessageBuilder
.
use irc_rust::Message; use std::error::Error; fn main() -> Result<(), Box<dyn Error>> { let message = Message::builder("CMD") .tag("key1", "value1") .tag("key2", "value2") .prefix("name", Some("user"), Some("host")) .param("param1").param("param2") .trailing("trailing") .build(); let tags = message.tags().unwrap().unwrap(); println!("key1={}", &tags["key1"]); // Prints 'key1=value1' Ok(()) }
You can create a new message from an existing message by calling the to_builder
method.
To alter existing parameters the set_param
method can be used.
use irc_rust::Message; use std::error::Error; fn main() -> Result<(), Box<dyn Error>> { let message = Message::from("@key=value :name!user@host CMD param1 :trailing!").to_builder()? .tag("key", "value2") .param("param2") .param("param4") .set_param(1, "param3") .build(); assert_eq!(message.to_string(), "@key=value2 :name!user@host CMD param1 param3 param4 :trailing!"); Ok(()) }
Implementations
impl Message
[src]
pub fn builder(command: &str) -> MessageBuilder<'_>
[src]
Creates a message builder as alternative to building an irc string before creating the message.
pub fn to_builder(&self) -> Result<MessageBuilder<'_>, InvalidIrcFormatError>
[src]
Creates a builder from this message. Only initializes fields already present in the message. By using this method a whole new Message will be created.
pub fn tags(&self) -> Result<Option<Tags<'_>>, InvalidIrcFormatError>
[src]
Returns tags if any are present.
pub fn prefix(&self) -> Result<Option<Prefix<'_>>, InvalidIrcFormatError>
[src]
Returns the Prefix if present.
pub fn command(&self) -> &str
[src]
Returns the command the message represents.
pub fn params(&self) -> Option<Params<'_>>
[src]
Returns the params if any are present.
Trait Implementations
impl Clone for Message
[src]
impl Debug for Message
[src]
impl Display for Message
[src]
impl Eq for Message
[src]
impl From<&'_ str> for Message
[src]
impl From<String> for Message
[src]
impl Hash for Message
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Message
[src]
fn cmp(&self, other: &Message) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<Message> for Message
[src]
impl PartialOrd<Message> for Message
[src]
fn partial_cmp(&self, other: &Message) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl StructuralEq for Message
[src]
impl StructuralPartialEq for Message
[src]
Auto Trait Implementations
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,