Skip to content

Commit 74d7673

Browse files
authored
chore: Use derive macro to implement default (#1762)
1 parent 1b3fa89 commit 74d7673

File tree

4 files changed

+8
-31
lines changed

4 files changed

+8
-31
lines changed

tonic-web/src/client.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,15 @@ use crate::call::content_types::GRPC_WEB;
1515
use crate::call::GrpcWebCall;
1616

1717
/// Layer implementing the grpc-web protocol for clients.
18-
#[derive(Debug, Clone)]
18+
#[derive(Debug, Default, Clone)]
1919
pub struct GrpcWebClientLayer {
2020
_priv: (),
2121
}
2222

2323
impl GrpcWebClientLayer {
2424
/// Create a new grpc-web for clients layer.
2525
pub fn new() -> GrpcWebClientLayer {
26-
Self { _priv: () }
27-
}
28-
}
29-
30-
impl Default for GrpcWebClientLayer {
31-
fn default() -> Self {
32-
Self::new()
26+
Self::default()
3327
}
3428
}
3529

tonic-web/src/layer.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,15 @@ use tower_layer::Layer;
44
use tower_service::Service;
55

66
/// Layer implementing the grpc-web protocol.
7-
#[derive(Debug, Clone)]
7+
#[derive(Debug, Default, Clone)]
88
pub struct GrpcWebLayer {
99
_priv: (),
1010
}
1111

1212
impl GrpcWebLayer {
1313
/// Create a new grpc-web layer.
1414
pub fn new() -> GrpcWebLayer {
15-
Self { _priv: () }
16-
}
17-
}
18-
19-
impl Default for GrpcWebLayer {
20-
fn default() -> Self {
21-
Self::new()
15+
Self::default()
2216
}
2317
}
2418

tonic/src/codec/compression.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,19 +276,14 @@ pub(crate) fn decompress(
276276
Ok(())
277277
}
278278

279-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
279+
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
280280
pub(crate) enum SingleMessageCompressionOverride {
281281
/// Inherit whatever compression is already configured. If the stream is compressed this
282282
/// message will also be configured.
283283
///
284284
/// This is the default.
285+
#[default]
285286
Inherit,
286287
/// Don't compress this message, even if compression is enabled on the stream.
287288
Disable,
288289
}
289-
290-
impl Default for SingleMessageCompressionOverride {
291-
fn default() -> Self {
292-
Self::Inherit
293-
}
294-
}

tonic/src/metadata/key.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct MetadataKey<VE: ValueEncoding> {
2424
}
2525

2626
/// A possible error when converting a `MetadataKey` from another type.
27-
#[derive(Debug)]
27+
#[derive(Debug, Default)]
2828
pub struct InvalidMetadataKey {
2929
_priv: (),
3030
}
@@ -180,7 +180,7 @@ impl<VE: ValueEncoding> fmt::Display for MetadataKey<VE> {
180180
impl InvalidMetadataKey {
181181
#[doc(hidden)]
182182
pub fn new() -> InvalidMetadataKey {
183-
InvalidMetadataKey { _priv: () }
183+
Self::default()
184184
}
185185
}
186186

@@ -275,12 +275,6 @@ impl fmt::Display for InvalidMetadataKey {
275275
}
276276
}
277277

278-
impl Default for InvalidMetadataKey {
279-
fn default() -> Self {
280-
Self::new()
281-
}
282-
}
283-
284278
impl Error for InvalidMetadataKey {}
285279

286280
#[cfg(test)]

0 commit comments

Comments
 (0)