From f109c6b455284620c216bfad6b03cf000b1c7014 Mon Sep 17 00:00:00 2001 From: dousamichal0807 Date: Sat, 16 Apr 2022 19:56:10 +0200 Subject: [PATCH] Updated library version, added `CompositeLogger::append` method. --- Cargo.toml | 2 +- src/auto.rs | 4 +++- src/loggers/composite.rs | 19 ++++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2c9509c..2176563 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "mdlog" authors = ["Michal DouĊĦa "] -version = "0.1.0" +version = "0.2.0" edition = "2021" [dependencies] diff --git a/src/auto.rs b/src/auto.rs index e713a65..c0e8caa 100644 --- a/src/auto.rs +++ b/src/auto.rs @@ -9,7 +9,9 @@ use std::io; /// /// Note that [`Logger`] trait does not specify how given message is logged nor /// where it should be logged to. -pub trait Logger { +/// +/// [`log`]: Logger::log +pub trait Logger: Send + Sync { /// Method for logging a message. /// /// # Parameters diff --git a/src/loggers/composite.rs b/src/loggers/composite.rs index a7bb107..3881131 100644 --- a/src/loggers/composite.rs +++ b/src/loggers/composite.rs @@ -21,9 +21,27 @@ impl CompositeLogger { /// Creates a new [`CompositeLogger`] with given capacity of the underlying /// [`Vec`]. See [`Vec::with_capacity`] method for more information. + /// + /// # Parameters + /// + /// - `capacity`: capacity of the underlying [`Vec`] pub fn with_capacity(capacity: usize) -> Self { Self(Vec::with_capacity(capacity)) } + + pub fn add(&mut self, logger: L) + where L: Logger { + self.0.push(logger) + } + + /// Merges `self` with another instance of [`CompositeLogger`]. + /// + /// # Parameters + /// + /// - `other`: the other instance of [`CompositeLogger`] to merge with + pub fn append(&mut self, mut other: Self) { + self.0.append(&mut other.0); + } } impl Logger for CompositeLogger { @@ -37,7 +55,6 @@ impl Logger for CompositeLogger { impl Deref for CompositeLogger { type Target = LoggerVec; - fn deref(&self) -> &LoggerVec { &self.0 }