Skip to content

Commit

Permalink
Merge pull request #21 from logdna/extend-lineMetaMut-trait-with-addi…
Browse files Browse the repository at this point in the history
…tional-accessors

Extend line meta mut trait with additional accessors
  • Loading branch information
c-nixon authored Apr 14, 2022
2 parents 9b65609 + 290e54e commit c452200
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "logdna-client"
version = "0.6.0"
version = "0.7.0"
authors = ["[email protected]"]
edition = "2018"
license = "MIT"
Expand Down
61 changes: 58 additions & 3 deletions src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ pub trait LineMetaMut: LineMeta {
fn set_labels(&mut self, labels: KeyValueMap) -> Result<(), LineMetaError>;
fn set_level(&mut self, level: String) -> Result<(), LineMetaError>;
fn set_meta(&mut self, meta: Value) -> Result<(), LineMetaError>;
fn get_annotations_mut(&mut self) -> &mut Option<KeyValueMap>;
fn get_app_mut(&mut self) -> &mut Option<String>;
fn get_env_mut(&mut self) -> &mut Option<String>;
fn get_file_mut(&mut self) -> &mut Option<String>;
fn get_host_mut(&mut self) -> &mut Option<String>;
fn get_labels_mut(&mut self) -> &mut Option<KeyValueMap>;
fn get_level_mut(&mut self) -> &mut Option<String>;
fn get_meta_mut(&mut self) -> &mut Option<Value>;
}

/// Represents a line that provides accessor to the underlying data buffer for manipulation.
Expand Down Expand Up @@ -589,6 +597,30 @@ impl LineMetaMut for LineBuilder {
self.meta = Some(meta);
Ok(())
}
fn get_annotations_mut(&mut self) -> &mut Option<KeyValueMap> {
&mut self.annotations
}
fn get_app_mut(&mut self) -> &mut Option<String> {
&mut self.app
}
fn get_env_mut(&mut self) -> &mut Option<String> {
&mut self.env
}
fn get_file_mut(&mut self) -> &mut Option<String> {
&mut self.file
}
fn get_host_mut(&mut self) -> &mut Option<String> {
&mut self.host
}
fn get_labels_mut(&mut self) -> &mut Option<KeyValueMap> {
&mut self.labels
}
fn get_level_mut(&mut self) -> &mut Option<String> {
&mut self.level
}
fn get_meta_mut(&mut self) -> &mut Option<Value> {
&mut self.meta
}
}

impl LineBufferMut for LineBuilder {
Expand Down Expand Up @@ -639,6 +671,30 @@ impl LineMetaMut for &mut LineBuilder {
self.meta = Some(meta);
Ok(())
}
fn get_annotations_mut(&mut self) -> &mut Option<KeyValueMap> {
&mut self.annotations
}
fn get_app_mut(&mut self) -> &mut Option<String> {
&mut self.app
}
fn get_env_mut(&mut self) -> &mut Option<String> {
&mut self.env
}
fn get_file_mut(&mut self) -> &mut Option<String> {
&mut self.file
}
fn get_host_mut(&mut self) -> &mut Option<String> {
&mut self.host
}
fn get_labels_mut(&mut self) -> &mut Option<KeyValueMap> {
&mut self.labels
}
fn get_level_mut(&mut self) -> &mut Option<String> {
&mut self.level
}
fn get_meta_mut(&mut self) -> &mut Option<Value> {
&mut self.meta
}
}

impl LineBufferMut for &mut LineBuilder {
Expand Down Expand Up @@ -761,11 +817,10 @@ impl Default for KeyValueMap {
Self::new()
}
}

impl From<BTreeMap<String, String>> for KeyValueMap {
fn from(map: BTreeMap<String, String>) -> Self {
Self {
0: HashMap::from_iter(map),
}
Self(HashMap::from_iter(map))
}
}

Expand Down

0 comments on commit c452200

Please sign in to comment.