From 74d7673b2f5a518ffc4b4d1eb34fb4258f5e4409 Mon Sep 17 00:00:00 2001 From: tottoto Date: Fri, 28 Jun 2024 22:14:53 +0900 Subject: [PATCH] chore: Use derive macro to implement default (#1762) --- tonic-web/src/client.rs | 10 ++-------- tonic-web/src/layer.rs | 10 ++-------- tonic/src/codec/compression.rs | 9 ++------- tonic/src/metadata/key.rs | 10 ++-------- 4 files changed, 8 insertions(+), 31 deletions(-) diff --git a/tonic-web/src/client.rs b/tonic-web/src/client.rs index 774fe5fdd..bd6391047 100644 --- a/tonic-web/src/client.rs +++ b/tonic-web/src/client.rs @@ -15,7 +15,7 @@ use crate::call::content_types::GRPC_WEB; use crate::call::GrpcWebCall; /// Layer implementing the grpc-web protocol for clients. -#[derive(Debug, Clone)] +#[derive(Debug, Default, Clone)] pub struct GrpcWebClientLayer { _priv: (), } @@ -23,13 +23,7 @@ pub struct GrpcWebClientLayer { impl GrpcWebClientLayer { /// Create a new grpc-web for clients layer. pub fn new() -> GrpcWebClientLayer { - Self { _priv: () } - } -} - -impl Default for GrpcWebClientLayer { - fn default() -> Self { - Self::new() + Self::default() } } diff --git a/tonic-web/src/layer.rs b/tonic-web/src/layer.rs index 7834f1990..553293825 100644 --- a/tonic-web/src/layer.rs +++ b/tonic-web/src/layer.rs @@ -4,7 +4,7 @@ use tower_layer::Layer; use tower_service::Service; /// Layer implementing the grpc-web protocol. -#[derive(Debug, Clone)] +#[derive(Debug, Default, Clone)] pub struct GrpcWebLayer { _priv: (), } @@ -12,13 +12,7 @@ pub struct GrpcWebLayer { impl GrpcWebLayer { /// Create a new grpc-web layer. pub fn new() -> GrpcWebLayer { - Self { _priv: () } - } -} - -impl Default for GrpcWebLayer { - fn default() -> Self { - Self::new() + Self::default() } } diff --git a/tonic/src/codec/compression.rs b/tonic/src/codec/compression.rs index 5edd35904..bf9f64f22 100644 --- a/tonic/src/codec/compression.rs +++ b/tonic/src/codec/compression.rs @@ -276,19 +276,14 @@ pub(crate) fn decompress( Ok(()) } -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] pub(crate) enum SingleMessageCompressionOverride { /// Inherit whatever compression is already configured. If the stream is compressed this /// message will also be configured. /// /// This is the default. + #[default] Inherit, /// Don't compress this message, even if compression is enabled on the stream. Disable, } - -impl Default for SingleMessageCompressionOverride { - fn default() -> Self { - Self::Inherit - } -} diff --git a/tonic/src/metadata/key.rs b/tonic/src/metadata/key.rs index e40660d60..d520b93b9 100644 --- a/tonic/src/metadata/key.rs +++ b/tonic/src/metadata/key.rs @@ -24,7 +24,7 @@ pub struct MetadataKey { } /// A possible error when converting a `MetadataKey` from another type. -#[derive(Debug)] +#[derive(Debug, Default)] pub struct InvalidMetadataKey { _priv: (), } @@ -180,7 +180,7 @@ impl fmt::Display for MetadataKey { impl InvalidMetadataKey { #[doc(hidden)] pub fn new() -> InvalidMetadataKey { - InvalidMetadataKey { _priv: () } + Self::default() } } @@ -275,12 +275,6 @@ impl fmt::Display for InvalidMetadataKey { } } -impl Default for InvalidMetadataKey { - fn default() -> Self { - Self::new() - } -} - impl Error for InvalidMetadataKey {} #[cfg(test)]