Skip to content

Commit

Permalink
Fixed compile error caused by improper lifetime bounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
dousamichal0807 committed Apr 16, 2022
1 parent ec37d97 commit 85925da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
15 changes: 4 additions & 11 deletions src/loggers/composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ use std::ops::DerefMut;
use crate::Logger;
use crate::LogLevel;

type LoggerVec = Vec<Box<dyn Logger + Send + Sync>>;

/// Represents a [`Logger`] that consists of many [`Logger`]s.
///
/// [`CompositeLogger`] is used through its [`Deref`] and [`DerefMut`]
/// implementations which yield a borrow to the inner [`Vec`] of [`Logger`]s.
pub struct CompositeLogger (LoggerVec);
pub struct CompositeLogger (Vec<Box<dyn Logger>>);

impl CompositeLogger {
/// Creates a new [`CompositeLogger`] instance.
Expand All @@ -46,11 +44,6 @@ impl CompositeLogger {
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
Expand All @@ -71,14 +64,14 @@ impl Logger for CompositeLogger {
}

impl Deref for CompositeLogger {
type Target = LoggerVec;
fn deref(&self) -> &LoggerVec {
type Target = Vec<Box<dyn Logger>>;
fn deref(&self) -> &Vec<Box<dyn Logger>> {
&self.0
}
}

impl DerefMut for CompositeLogger {
fn deref_mut(&mut self) -> &mut LoggerVec {
fn deref_mut(&mut self) -> &mut Vec<Box<dyn Logger>> {
&mut self.0
}
}
20 changes: 13 additions & 7 deletions src/loggers/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ use crate::LogLevel;
/// output stream. The output stream can be anything, from [`Stdout`] to [`File`] or
/// [`TcpStream`].
///
/// [`File`]: std::fs::File
/// [`Stdout`]: std::io::Stdout
/// [`TcpStream`]: std::net::TcpStream
///
/// # Usage
///
/// ```rust
Expand All @@ -52,14 +48,22 @@ use crate::LogLevel;
/// logger.log(LogLevel::Fatal, "NO! FATAL ERROR! Application is shut down!");
/// }
/// ```
///
/// [`File`]: std::fs::File
/// [`Stdout`]: std::io::Stdout
/// [`TcpStream`]: std::net::TcpStream
pub struct TextLogger<W>
where W: Write {
where
W: Send + Sync + Write
{
min_log_level: LogLevel,
writer: W,
}

impl<W> TextLogger<W>
where W: Write {
where
W: Write + Send + Sync
{
/// Creates a new [`TextLogger`] instance with given name, minimum log level and
/// output stream.
///
Expand All @@ -82,7 +86,9 @@ impl<W> TextLogger<W>
}

impl<W> Logger for TextLogger<W>
where W: Write {
where
W: Write + Send + Sync
{
fn log(&mut self, log_level: LogLevel, message: &str) -> io::Result<()> {
// Do not do anything if log level is too low:
if log_level < self.min_log_level { return Result::Ok(()) }
Expand Down

0 comments on commit 85925da

Please sign in to comment.