From 14318bc2ef5b7abd72e467ff12f93d1af6fb83af Mon Sep 17 00:00:00 2001 From: tison Date: Tue, 15 Oct 2024 09:38:51 +0800 Subject: [PATCH] tidy impl Signed-off-by: tison --- src/encoder/layout_wrapping.rs | 8 +++++--- src/layout/custom.rs | 8 -------- src/layout/json.rs | 8 -------- src/layout/text.rs | 8 -------- 4 files changed, 5 insertions(+), 27 deletions(-) diff --git a/src/encoder/layout_wrapping.rs b/src/encoder/layout_wrapping.rs index fa2e40b..6313d0b 100644 --- a/src/encoder/layout_wrapping.rs +++ b/src/encoder/layout_wrapping.rs @@ -40,8 +40,10 @@ impl From for Encoder { } } -impl From for Encoder { - fn from(layout: Layout) -> Self { - LayoutWrappingEncoder::new(layout).into() +impl> From for Encoder { + fn from(layout: L) -> Self { + let layout = layout.into(); + let encoder = LayoutWrappingEncoder::new(layout); + Encoder::LayoutWrapping(encoder) } } diff --git a/src/layout/custom.rs b/src/layout/custom.rs index 17ff05e..acf9449 100644 --- a/src/layout/custom.rs +++ b/src/layout/custom.rs @@ -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`. @@ -64,9 +62,3 @@ impl From for Layout { Layout::Custom(layout) } } - -impl From for Encoder { - fn from(layout: CustomLayout) -> Self { - LayoutWrappingEncoder::new(layout.into()).into() - } -} diff --git a/src/layout/json.rs b/src/layout/json.rs index 78d762a..fd3df93 100644 --- a/src/layout/json.rs +++ b/src/layout/json.rs @@ -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. /// @@ -50,9 +48,3 @@ impl From for Layout { Layout::Json(layout) } } - -impl From for Encoder { - fn from(layout: JsonLayout) -> Self { - LayoutWrappingEncoder::new(layout.into()).into() - } -} diff --git a/src/layout/text.rs b/src/layout/text.rs index 48a936c..0a9a229 100644 --- a/src/layout/text.rs +++ b/src/layout/text.rs @@ -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. /// @@ -168,12 +166,6 @@ impl From for Layout { } } -impl From 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> {