From: Kostya Shishkov Date: Tue, 3 Feb 2026 17:56:53 +0000 (+0100) Subject: replace ToString with Display implementation X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=2d465ddb683b01a543b67a3a6323b7c8072b5003;p=nihav.git replace ToString with Display implementation --- diff --git a/nihav-commonfmt/src/codecs/cinepakenc.rs b/nihav-commonfmt/src/codecs/cinepakenc.rs index 8d78fb3..f2b9049 100644 --- a/nihav-commonfmt/src/codecs/cinepakenc.rs +++ b/nihav-commonfmt/src/codecs/cinepakenc.rs @@ -218,12 +218,12 @@ enum QuantMode { MedianCut, } -impl std::string::ToString for QuantMode { - fn to_string(&self) -> String { +impl std::fmt::Display for QuantMode { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { match *self { - QuantMode::ELBG => "elbg".to_string(), - QuantMode::Fast => "fast".to_string(), - QuantMode::MedianCut => "mediancut".to_string(), + QuantMode::ELBG => write!(f, "elbg"), + QuantMode::Fast => write!(f, "fast"), + QuantMode::MedianCut => write!(f, "mediancut"), } } } diff --git a/nihav-commonfmt/src/codecs/gifenc.rs b/nihav-commonfmt/src/codecs/gifenc.rs index 4a1e2b7..c67fb6b 100644 --- a/nihav-commonfmt/src/codecs/gifenc.rs +++ b/nihav-commonfmt/src/codecs/gifenc.rs @@ -20,12 +20,12 @@ enum CompressionLevel { Best } -impl std::string::ToString for CompressionLevel { - fn to_string(&self) -> String { +impl std::fmt::Display for CompressionLevel { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { match *self { - CompressionLevel::None => "none".to_string(), - CompressionLevel::Fast => "fast".to_string(), - CompressionLevel::Best => "best".to_string(), + CompressionLevel::None => write!(f, "none"), + CompressionLevel::Fast => write!(f, "fast"), + CompressionLevel::Best => write!(f, "best"), } } } diff --git a/nihav-core/src/codecs/mod.rs b/nihav-core/src/codecs/mod.rs index 5a2b945..2009901 100644 --- a/nihav-core/src/codecs/mod.rs +++ b/nihav-core/src/codecs/mod.rs @@ -227,12 +227,12 @@ impl FromStr for FrameSkipMode { } } -impl ToString for FrameSkipMode { - fn to_string(&self) -> String { +impl std::fmt::Display for FrameSkipMode { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { match *self { - FrameSkipMode::None => FRAME_SKIP_OPTION_VAL_NONE.to_string(), - FrameSkipMode::KeyframesOnly => FRAME_SKIP_OPTION_VAL_KEYFRAME.to_string(), - FrameSkipMode::IntraOnly => FRAME_SKIP_OPTION_VAL_INTRA.to_string(), + FrameSkipMode::None => write!(f, "{FRAME_SKIP_OPTION_VAL_NONE}"), + FrameSkipMode::KeyframesOnly => write!(f, "{FRAME_SKIP_OPTION_VAL_KEYFRAME}"), + FrameSkipMode::IntraOnly => write!(f, "{FRAME_SKIP_OPTION_VAL_INTRA}"), } } } diff --git a/nihav-core/src/compr/deflate.rs b/nihav-core/src/compr/deflate.rs index 72c583b..eabfa63 100644 --- a/nihav-core/src/compr/deflate.rs +++ b/nihav-core/src/compr/deflate.rs @@ -1955,13 +1955,13 @@ impl std::str::FromStr for DeflateMode { } } -impl ToString for DeflateMode { - fn to_string(&self) -> String { +impl std::fmt::Display for DeflateMode { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { match *self { - DeflateMode::NoCompr => DEFLATE_MODE_NONE.to_string(), - DeflateMode::Fast => DEFLATE_MODE_FAST.to_string(), - DeflateMode::Better => DEFLATE_MODE_BETTER.to_string(), - DeflateMode::Best => DEFLATE_MODE_BEST.to_string(), + DeflateMode::NoCompr => write!(f, "{DEFLATE_MODE_NONE}"), + DeflateMode::Fast => write!(f, "{DEFLATE_MODE_FAST}"), + DeflateMode::Better => write!(f, "{DEFLATE_MODE_BETTER}"), + DeflateMode::Best => write!(f, "{DEFLATE_MODE_BEST}"), } } } diff --git a/nihav-duck/src/codecs/truemotion1enc.rs b/nihav-duck/src/codecs/truemotion1enc.rs index 2ebd567..bdf710f 100644 --- a/nihav-duck/src/codecs/truemotion1enc.rs +++ b/nihav-duck/src/codecs/truemotion1enc.rs @@ -25,13 +25,13 @@ impl FromStr for BlockMode { } } -impl ToString for BlockMode { - fn to_string(&self) -> String { +impl std::fmt::Display for BlockMode { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { match *self { - BlockMode::FourByFour => "4x4".to_string(), - BlockMode::FourByTwo => "4x2".to_string(), - BlockMode::TwoByFour => "2x4".to_string(), - BlockMode::TwoByTwo => "2x2".to_string(), + BlockMode::FourByFour => write!(f, "4x4"), + BlockMode::FourByTwo => write!(f, "4x2"), + BlockMode::TwoByFour => write!(f, "2x4"), + BlockMode::TwoByTwo => write!(f, "2x2"), } } } @@ -56,12 +56,12 @@ impl FromStr for OptionMode { } } -impl ToString for OptionMode { - fn to_string(&self) -> String { +impl std::fmt::Display for OptionMode { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { match *self { - OptionMode::Off => "off".to_string(), - OptionMode::On => "on".to_string(), - OptionMode::Auto => "auto".to_string(), + OptionMode::Off => write!(f, "off"), + OptionMode::On => write!(f, "on"), + OptionMode::Auto => write!(f, "auto"), } } } diff --git a/nihav-rad/src/codecs/binkvidenc.rs b/nihav-rad/src/codecs/binkvidenc.rs index b3cbbf1..c47aba6 100644 --- a/nihav-rad/src/codecs/binkvidenc.rs +++ b/nihav-rad/src/codecs/binkvidenc.rs @@ -26,15 +26,15 @@ enum DoublingMode { Width2XIlace } -impl std::string::ToString for DoublingMode { - fn to_string(&self) -> String { +impl std::fmt::Display for DoublingMode { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { match *self { - DoublingMode::None => "none".to_string(), - DoublingMode::Height2X => "height2x".to_string(), - DoublingMode::HeightIlace => "height_il".to_string(), - DoublingMode::Scale2X => "scale2x".to_string(), - DoublingMode::Width2X => "width2x".to_string(), - DoublingMode::Width2XIlace => "width2x_il".to_string(), + DoublingMode::None => write!(f, "none"), + DoublingMode::Height2X => write!(f, "height2x"), + DoublingMode::HeightIlace => write!(f, "height_il"), + DoublingMode::Scale2X => write!(f, "scale2x"), + DoublingMode::Width2X => write!(f, "width2x"), + DoublingMode::Width2XIlace => write!(f, "width2x_il"), } } } @@ -93,8 +93,10 @@ impl std::str::FromStr for BlockMode { } } -impl std::string::ToString for BlockMode { - fn to_string(&self) -> String { BLOCK_MODE_NAMES[usize::from(*self)].to_string() } +impl std::fmt::Display for BlockMode { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { + write!(f, "{}", BLOCK_MODE_NAMES[usize::from(*self)]) + } } impl BlockMode {