@@ -95,7 +95,7 @@ impl EnvelopeFormat {
9595}
9696
9797/// Configuration for encoding an envelope.
98- #[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
98+ #[ derive( Clone , Copy , Debug , Default , Eq , PartialEq ) ]
9999#[ non_exhaustive]
100100pub struct EnvelopeConfig {
101101 /// The format to use for the payload.
@@ -105,19 +105,29 @@ pub struct EnvelopeConfig {
105105 pub zstd : Option < ZstdConfig > ,
106106}
107107
108- impl Default for EnvelopeConfig {
109- fn default ( ) -> Self {
110- let format = Default :: default ( ) ;
111- let zstd = if cfg ! ( feature = "zstd" ) {
112- Some ( ZstdConfig :: default ( ) )
113- } else {
114- None
115- } ;
116- Self { format, zstd }
108+ impl EnvelopeConfig {
109+ /// Create a new envelope configuration with the specified format.
110+ /// `zstd` compression is disabled by default.
111+ pub fn new ( format : EnvelopeFormat ) -> Self {
112+ Self {
113+ format,
114+ ..Default :: default ( )
115+ }
116+ }
117+
118+ /// Set the zstd compression configuration for the envelope.
119+ pub fn with_zstd ( self , zstd : ZstdConfig ) -> Self {
120+ Self {
121+ zstd : Some ( zstd) ,
122+ ..self
123+ }
124+ }
125+
126+ /// Disable zstd compression in the envelope configuration.
127+ pub fn disable_compression ( self ) -> Self {
128+ Self { zstd : None , ..self }
117129 }
118- }
119130
120- impl EnvelopeConfig {
121131 /// Create a new envelope header with the specified configuration.
122132 pub ( super ) fn make_header ( & self ) -> EnvelopeHeader {
123133 EnvelopeHeader {
@@ -162,6 +172,12 @@ pub struct ZstdConfig {
162172}
163173
164174impl ZstdConfig {
175+ /// Create a new zstd configuration with the specified compression level.
176+ pub fn new ( level : u8 ) -> Self {
177+ Self {
178+ level : NonZeroU8 :: new ( level) ,
179+ }
180+ }
165181 /// Create a new zstd configuration with default compression level.
166182 #[ must_use]
167183 pub const fn default_level ( ) -> Self {
0 commit comments