Skip to content

Commit

Permalink
Added CompositeLogger::append method.
Browse files Browse the repository at this point in the history
  • Loading branch information
dousamichal0807 committed Apr 16, 2022
1 parent 1308c74 commit 3740d77
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "mdlog"
authors = ["Michal Douša <[email protected]>"]
version = "0.1.0"
version = "0.2.0"
edition = "2021"

[dependencies]
Expand Down
4 changes: 3 additions & 1 deletion src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion src/loggers/composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<L>(&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 {
Expand All @@ -37,7 +55,6 @@ impl Logger for CompositeLogger {

impl Deref for CompositeLogger {
type Target = LoggerVec;

fn deref(&self) -> &LoggerVec {
&self.0
}
Expand Down

0 comments on commit 3740d77

Please sign in to comment.