Skip to content

Commit

Permalink
adding params (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
HosMercury committed Mar 9, 2024
1 parent ade8b11 commit 1813abf
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

use core::fmt;
use std::{
collections::VecDeque,
collections::{HashMap, VecDeque},
future::Future,
pin::Pin,
sync::{
Expand Down Expand Up @@ -98,6 +98,10 @@ pub struct Message {
/// The message itself.
#[serde(rename = "m")]
pub message: String,

/// adding extra args
#[serde(rename = "a")]
pub extra_args: HashMap<String, String>,
}

impl fmt::Display for Message {
Expand All @@ -106,6 +110,14 @@ impl fmt::Display for Message {
}
}

impl Message {
/// adding extra arg to the message
pub fn add_arg(mut self, name: String, value: impl Into<String>) -> Self {
self.extra_args.insert(name, value.into());
self
}
}

type MessageQueue = VecDeque<Message>;

/// Enumeration of message levels.
Expand Down Expand Up @@ -203,6 +215,8 @@ impl Messages {
data.pending_messages.push_back(Message {
message: message.into(),
level,
// default initial value for extra args
extra_args: HashMap::new(),
});
}

Expand Down

0 comments on commit 1813abf

Please sign in to comment.