Skip to content

Commit

Permalink
tidy impl
Browse files Browse the repository at this point in the history
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun committed Oct 15, 2024
1 parent 8ccfbea commit 14318bc
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 27 deletions.
8 changes: 5 additions & 3 deletions src/encoder/layout_wrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ impl From<LayoutWrappingEncoder> for Encoder {
}
}

impl From<Layout> for Encoder {
fn from(layout: Layout) -> Self {
LayoutWrappingEncoder::new(layout).into()
impl<L: Into<Layout>> From<L> for Encoder {
fn from(layout: L) -> Self {
let layout = layout.into();
let encoder = LayoutWrappingEncoder::new(layout);
Encoder::LayoutWrapping(encoder)
}
}
8 changes: 0 additions & 8 deletions src/layout/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ use std::fmt::Formatter;

use log::Record;

use crate::encoder::LayoutWrappingEncoder;
use crate::layout::Layout;
use crate::Encoder;

// TODO(tisonkun): use trait alias when it's stable - https://github.com/rust-lang/rust/issues/41517
// then we can use the alias for both `dyn` and `impl`.
Expand Down Expand Up @@ -64,9 +62,3 @@ impl From<CustomLayout> for Layout {
Layout::Custom(layout)
}
}

impl From<CustomLayout> for Encoder {
fn from(layout: CustomLayout) -> Self {
LayoutWrappingEncoder::new(layout.into()).into()
}
}
8 changes: 0 additions & 8 deletions src/layout/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
use jiff::tz::TimeZone;
use log::Record;

use crate::encoder::LayoutWrappingEncoder;
use crate::layout::Layout;
use crate::Encoder;

/// A layout that formats log record as JSON lines.
///
Expand Down Expand Up @@ -50,9 +48,3 @@ impl From<JsonLayout> for Layout {
Layout::Json(layout)
}
}

impl From<JsonLayout> for Encoder {
fn from(layout: JsonLayout) -> Self {
LayoutWrappingEncoder::new(layout.into()).into()
}
}
8 changes: 0 additions & 8 deletions src/layout/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ use jiff::Timestamp;
use jiff::Zoned;
use log::Level;

use crate::encoder::LayoutWrappingEncoder;
use crate::layout::KvDisplay;
use crate::layout::Layout;
use crate::Encoder;

/// A layout that formats log record as text.
///
Expand Down Expand Up @@ -168,12 +166,6 @@ impl From<TextLayout> for Layout {
}
}

impl From<TextLayout> for Encoder {
fn from(layout: TextLayout) -> Self {
LayoutWrappingEncoder::new(layout.into()).into()
}
}

// obtain filename only from record's full file path
// reason: the module is already logged + full file path is noisy for text layout
fn filename<'a>(record: &'a log::Record<'a>) -> Cow<'a, str> {
Expand Down

0 comments on commit 14318bc

Please sign in to comment.