| 1 | //! Raw in-memory stream compression/decompression. |
| 2 | //! |
| 3 | //! This module defines a `Decoder` and an `Encoder` to decode/encode streams |
| 4 | //! of data using buffers. |
| 5 | //! |
| 6 | //! They are mostly thin wrappers around `zstd_safe::{DCtx, CCtx}`. |
| 7 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/; |
| 8 | |
| 9 | pub use zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::{CParameterrust-analyzer cargo zstd-safe 7.2.2 CParameter#, DParameterrust-analyzer cargo zstd-safe 7.2.2 DParameter#, InBufferrust-analyzer cargo zstd-safe 7.2.2 InBuffer#, OutBufferrust-analyzer cargo zstd-safe 7.2.2 OutBuffer#, WriteBufrust-analyzer cargo zstd-safe 7.2.2 WriteBuf#}; |
| 10 | |
| 11 | use craterust-analyzer cargo zstd 0.13.3 crate/::dictrust-analyzer cargo zstd 0.13.3 dict/::{DecoderDictionaryrust-analyzer cargo zstd 0.13.3 dict/DecoderDictionary#, EncoderDictionaryrust-analyzer cargo zstd 0.13.3 dict/EncoderDictionary#}; |
| 12 | use craterust-analyzer cargo zstd 0.13.3 crate/::map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().; |
| 13 | |
| 14 | /// Represents an abstract compression/decompression operation. |
| 15 | /// |
| 16 | /// This trait covers both `Encoder` and `Decoder`. |
| 17 | pub trait Operationrust-analyzer cargo zstd 0.13.3 stream/raw/Operation# { |
| 18 | /// Performs a single step of this operation. |
| 19 | /// |
| 20 | /// Should return a hint for the next input size. |
| 21 | /// |
| 22 | /// If the result is `Ok(0)`, it may indicate that a frame was just |
| 23 | /// finished. |
| 24 | fn runrust-analyzer cargo zstd 0.13.3 stream/raw/Operation#run().<C: WriteBufrust-analyzer cargo zstd-safe 7.2.2 WriteBuf# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>( |
| 25 | &mut self, |
| 26 | input: &mut InBufferrust-analyzer cargo zstd-safe 7.2.2 InBuffer#<'_>, |
| 27 | output: &mut OutBufferrust-analyzer cargo zstd-safe 7.2.2 OutBuffer#<'_, C>, |
| 28 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize>; |
| 29 | |
| 30 | /// Performs a single step of this operation. |
| 31 | /// |
| 32 | /// This is a comvenience wrapper around `Operation::run` if you don't |
| 33 | /// want to deal with `InBuffer`/`OutBuffer`. |
| 34 | fn run_on_buffersrust-analyzer cargo zstd 0.13.3 stream/raw/Operation#run_on_buffers().( |
| 35 | &mut self, |
| 36 | input: &[u8], |
| 37 | output: &mut [u8], |
| 38 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Statusrust-analyzer cargo zstd 0.13.3 stream/raw/Status#> { |
| 39 | let mut input = InBufferrust-analyzer cargo zstd-safe 7.2.2 InBuffer#::aroundrust-analyzer cargo zstd-safe 7.2.2 impl#[`InBuffer<'a>`]around().(input); |
| 40 | let mut output = OutBufferrust-analyzer cargo zstd-safe 7.2.2 OutBuffer#::aroundrust-analyzer cargo zstd-safe 7.2.2 impl#[`OutBuffer<'a, C>`]around().(output); |
| 41 | |
| 42 | let remaining = self.runrust-analyzer cargo zstd 0.13.3 stream/raw/Operation#run().(&mut input, &mut output)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 43 | |
| 44 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Statusrust-analyzer cargo zstd 0.13.3 stream/raw/Status# { |
| 45 | remainingrust-analyzer cargo zstd 0.13.3 stream/raw/Status#remaining., |
| 46 | bytes_readrust-analyzer cargo zstd 0.13.3 stream/raw/Status#bytes_read.: input.posrust-analyzer cargo zstd-safe 7.2.2 impl#[`InBuffer<'a>`]pos().(), |
| 47 | bytes_writtenrust-analyzer cargo zstd 0.13.3 stream/raw/Status#bytes_written.: output.posrust-analyzer cargo zstd-safe 7.2.2 impl#[`OutBuffer<'a, C>`]pos().(), |
| 48 | }) |
| 49 | } |
| 50 | |
| 51 | /// Flushes any internal buffer, if any. |
| 52 | /// |
| 53 | /// Returns the number of bytes still in the buffer. |
| 54 | /// To flush entirely, keep calling until it returns `Ok(0)`. |
| 55 | fn flushrust-analyzer cargo zstd 0.13.3 stream/raw/Operation#flush().<C: WriteBufrust-analyzer cargo zstd-safe 7.2.2 WriteBuf# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>( |
| 56 | &mut self, |
| 57 | output: &mut OutBufferrust-analyzer cargo zstd-safe 7.2.2 OutBuffer#<'_, C>, |
| 58 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> { |
| 59 | let _ = output; |
| 60 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0) |
| 61 | } |
| 62 | |
| 63 | /// Prepares the operation for a new frame. |
| 64 | /// |
| 65 | /// This is hopefully cheaper than creating a new operation. |
| 66 | fn reinitrust-analyzer cargo zstd 0.13.3 stream/raw/Operation#reinit().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 67 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 68 | } |
| 69 | |
| 70 | /// Finishes the operation, writing any footer if necessary. |
| 71 | /// |
| 72 | /// Returns the number of bytes still to write. |
| 73 | /// |
| 74 | /// Keep calling this method until it returns `Ok(0)`, |
| 75 | /// and then don't ever call this method. |
| 76 | fn finishrust-analyzer cargo zstd 0.13.3 stream/raw/Operation#finish().<C: WriteBufrust-analyzer cargo zstd-safe 7.2.2 WriteBuf# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>( |
| 77 | &mut self, |
| 78 | output: &mut OutBufferrust-analyzer cargo zstd-safe 7.2.2 OutBuffer#<'_, C>, |
| 79 | finished_frame: bool, |
| 80 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> { |
| 81 | let _ = output; |
| 82 | let _ = finished_frame; |
| 83 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /// Dummy operation that just copies its input to the output. |
| 88 | pub struct NoOprust-analyzer cargo zstd 0.13.3 stream/raw/NoOp#; |
| 89 | |
| 90 | impl Operationrust-analyzer cargo zstd 0.13.3 stream/raw/Operation# for NoOprust-analyzer cargo zstd 0.13.3 stream/raw/NoOp# { |
| 91 | fn runrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[NoOp][Operation]run().<C: WriteBufrust-analyzer cargo zstd-safe 7.2.2 WriteBuf# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>( |
| 92 | &mut self, |
| 93 | input: &mut InBufferrust-analyzer cargo zstd-safe 7.2.2 InBuffer#<'_>, |
| 94 | output: &mut OutBufferrust-analyzer cargo zstd-safe 7.2.2 OutBuffer#<'_, C>, |
| 95 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> { |
| 96 | // Skip the prelude |
| 97 | let src = &input.srcrust-analyzer cargo zstd-safe 7.2.2 InBuffer#src.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().input.posrust-analyzer cargo zstd-safe 7.2.2 InBuffer#pos...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 98 | // Safe because `output.pos() <= output.capacity()`. |
| 99 | let output_pos = output.posrust-analyzer cargo zstd-safe 7.2.2 impl#[`OutBuffer<'a, C>`]pos().(); |
| 100 | let dst = unsafe { output.as_mut_ptrrust-analyzer cargo zstd-safe 7.2.2 impl#[`OutBuffer<'a, C>`]as_mut_ptr().().addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]add().(output_pos) }; |
| 101 | |
| 102 | // Ignore anything past the end |
| 103 | let len = usize::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#min().(src.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), output.capacityrust-analyzer cargo zstd-safe 7.2.2 impl#[`OutBuffer<'a, C>`]capacity().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().output_pos); |
| 104 | let src = &src[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 105 | |
| 106 | // Safe because: |
| 107 | // * `len` is less than either of the two lengths |
| 108 | // * `src` and `dst` do not overlap because we have `&mut` to each. |
| 109 | unsafe { stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::copy_nonoverlappingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/copy_nonoverlapping().(src.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().(), dst, len) }; |
| 110 | input.set_posrust-analyzer cargo zstd-safe 7.2.2 impl#[`InBuffer<'a>`]set_pos().(input.posrust-analyzer cargo zstd-safe 7.2.2 impl#[`InBuffer<'a>`]pos().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().len); |
| 111 | unsafe { output.set_posrust-analyzer cargo zstd-safe 7.2.2 impl#[`OutBuffer<'a, C>`]set_pos().(output_pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().len) }; |
| 112 | |
| 113 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /// Describes the result of an operation. |
| 118 | pub struct Statusrust-analyzer cargo zstd 0.13.3 stream/raw/Status# { |
| 119 | /// Number of bytes expected for next input. |
| 120 | /// |
| 121 | /// * If `remaining = 0`, then we are at the end of a frame. |
| 122 | /// * If `remaining > 0`, then it's just a hint for how much there is still |
| 123 | /// to read. |
| 124 | pub remainingrust-analyzer cargo zstd 0.13.3 stream/raw/Status#remaining.: usize, |
| 125 | |
| 126 | /// Number of bytes read from the input. |
| 127 | pub bytes_readrust-analyzer cargo zstd 0.13.3 stream/raw/Status#bytes_read.: usize, |
| 128 | |
| 129 | /// Number of bytes written to the output. |
| 130 | pub bytes_writtenrust-analyzer cargo zstd 0.13.3 stream/raw/Status#bytes_written.: usize, |
| 131 | } |
| 132 | |
| 133 | /// An in-memory decoder for streams of data. |
| 134 | pub struct Decoderrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#<'a> { |
| 135 | contextrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#context.: MaybeOwnedDCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#<'a>, |
| 136 | } |
| 137 | |
| 138 | impl Decoderrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#<'static> { |
| 139 | /// Creates a new decoder. |
| 140 | pub fn newrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'static>`]new().() -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'static>`]> { |
| 141 | Selfrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'static>`]::with_dictionaryrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'static>`]with_dictionary().(&[]) |
| 142 | } |
| 143 | |
| 144 | /// Creates a new decoder initialized with the given dictionary. |
| 145 | pub fn with_dictionaryrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'static>`]with_dictionary().(dictionary: &[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'static>`]> { |
| 146 | let mut context = zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::DCtxrust-analyzer cargo zstd-safe 7.2.2 DCtx#::createrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]create().(); |
| 147 | context.initrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]init().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 148 | context |
| 149 | .load_dictionaryrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]load_dictionary().(dictionary) |
| 150 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 151 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Decoderrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder# { |
| 152 | contextrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#context.: MaybeOwnedDCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#::Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#Owned#(context), |
| 153 | }) |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | impl<'a> Decoderrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#<'a> { |
| 158 | /// Creates a new decoder which employs the provided context for deserialization. |
| 159 | pub fn with_contextrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'a>`]with_context().(context: &'a mut zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::DCtxrust-analyzer cargo zstd-safe 7.2.2 DCtx#<'static>) -> Selfrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'a>`] { |
| 160 | Selfrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'a>`] { |
| 161 | contextrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#context.: MaybeOwnedDCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#::Borrowedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#Borrowed#(context), |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | /// Creates a new decoder, using an existing `DecoderDictionary`. |
| 166 | pub fn with_prepared_dictionaryrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'a>`]with_prepared_dictionary().<'b>( |
| 167 | dictionary: &DecoderDictionaryrust-analyzer cargo zstd 0.13.3 dict/DecoderDictionary#<'b>, |
| 168 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'a>`]> |
| 169 | where |
| 170 | 'b: 'a, |
| 171 | { |
| 172 | let mut context = zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::DCtxrust-analyzer cargo zstd-safe 7.2.2 DCtx#::createrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]create().(); |
| 173 | context |
| 174 | .ref_ddictrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]ref_ddict().(dictionary.as_ddictrust-analyzer cargo zstd 0.13.3 dict/impl#[`DecoderDictionary<'a>`]as_ddict().()) |
| 175 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 176 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Decoderrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder# { |
| 177 | contextrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#context.: MaybeOwnedDCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#::Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#Owned#(context), |
| 178 | }) |
| 179 | } |
| 180 | |
| 181 | /// Creates a new decoder, using a ref prefix |
| 182 | pub fn with_ref_prefixrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'a>`]with_ref_prefix().<'b>(ref_prefix: &'b [u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'a>`]> |
| 183 | where |
| 184 | 'b: 'a, |
| 185 | { |
| 186 | let mut context = zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::DCtxrust-analyzer cargo zstd-safe 7.2.2 DCtx#::createrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]create().(); |
| 187 | context.ref_prefixrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]ref_prefix().(ref_prefix).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 188 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Decoderrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder# { |
| 189 | contextrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#context.: MaybeOwnedDCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#::Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#Owned#(context), |
| 190 | }) |
| 191 | } |
| 192 | |
| 193 | /// Sets a decompression parameter for this decoder. |
| 194 | pub fn set_parameterrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'a>`]set_parameter().(&mut self, parameter: DParameterrust-analyzer cargo zstd-safe 7.2.2 DParameter#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 195 | match &mut self.contextrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#context. { |
| 196 | MaybeOwnedDCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#::Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#Owned#(x) => x.set_parameterrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]set_parameter().(parameter), |
| 197 | MaybeOwnedDCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#::Borrowedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#Borrowed#(x) => x.set_parameterrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]set_parameter().(parameter), |
| 198 | } |
| 199 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 200 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | impl Operationrust-analyzer cargo zstd 0.13.3 stream/raw/Operation# for Decoderrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#<'_> { |
| 205 | fn runrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'_>`][Operation]run().<C: WriteBufrust-analyzer cargo zstd-safe 7.2.2 WriteBuf# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>( |
| 206 | &mut self, |
| 207 | input: &mut InBufferrust-analyzer cargo zstd-safe 7.2.2 InBuffer#<'_>, |
| 208 | output: &mut OutBufferrust-analyzer cargo zstd-safe 7.2.2 OutBuffer#<'_, C>, |
| 209 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> { |
| 210 | match &mut self.contextrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#context. { |
| 211 | MaybeOwnedDCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#::Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#Owned#(x) => x.decompress_streamrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]decompress_stream().(output, input), |
| 212 | MaybeOwnedDCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#::Borrowedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#Borrowed#(x) => x.decompress_streamrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]decompress_stream().(output, input), |
| 213 | } |
| 214 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().) |
| 215 | } |
| 216 | |
| 217 | fn flushrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'_>`][Operation]flush().<C: WriteBufrust-analyzer cargo zstd-safe 7.2.2 WriteBuf# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>( |
| 218 | &mut self, |
| 219 | output: &mut OutBufferrust-analyzer cargo zstd-safe 7.2.2 OutBuffer#<'_, C>, |
| 220 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> { |
| 221 | // To flush, we just offer no additional input. |
| 222 | self.runrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'_>`][Operation]run().(&mut InBufferrust-analyzer cargo zstd-safe 7.2.2 InBuffer#::aroundrust-analyzer cargo zstd-safe 7.2.2 impl#[`InBuffer<'a>`]around().(&[]), output)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 223 | |
| 224 | // We don't _know_ how much (decompressed data) there is still in buffer. |
| 225 | if output.posrust-analyzer cargo zstd-safe 7.2.2 impl#[`OutBuffer<'a, C>`]pos().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().output.capacityrust-analyzer cargo zstd-safe 7.2.2 impl#[`OutBuffer<'a, C>`]capacity().() { |
| 226 | // We only know when there's none (the output buffer is not full). |
| 227 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0) |
| 228 | } else { |
| 229 | // Otherwise, pretend there's still "1 byte" remaining. |
| 230 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(1) |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | fn reinitrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'_>`][Operation]reinit().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 235 | match &mut self.contextrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#context. { |
| 236 | MaybeOwnedDCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#::Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#Owned#(x) => { |
| 237 | x.resetrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]reset().(zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::ResetDirectiverust-analyzer cargo zstd-safe 7.2.2 ResetDirective#::SessionOnlyrust-analyzer cargo zstd-safe 7.2.2 ResetDirective#SessionOnly#) |
| 238 | } |
| 239 | MaybeOwnedDCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#::Borrowedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#Borrowed#(x) => { |
| 240 | x.resetrust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]reset().(zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::ResetDirectiverust-analyzer cargo zstd-safe 7.2.2 ResetDirective#::SessionOnlyrust-analyzer cargo zstd-safe 7.2.2 ResetDirective#SessionOnly#) |
| 241 | } |
| 242 | } |
| 243 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 244 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 245 | } |
| 246 | |
| 247 | fn finishrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'_>`][Operation]finish().<C: WriteBufrust-analyzer cargo zstd-safe 7.2.2 WriteBuf# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>( |
| 248 | &mut self, |
| 249 | _output: &mut OutBufferrust-analyzer cargo zstd-safe 7.2.2 OutBuffer#<'_, C>, |
| 250 | finished_frame: bool, |
| 251 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> { |
| 252 | if finished_frame { |
| 253 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0) |
| 254 | } else { |
| 255 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().( |
| 256 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::UnexpectedEofrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#UnexpectedEof#, |
| 257 | "incomplete frame", |
| 258 | )) |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | /// An in-memory encoder for streams of data. |
| 264 | pub struct Encoderrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#<'a> { |
| 265 | contextrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#context.: MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#<'a>, |
| 266 | } |
| 267 | |
| 268 | impl Encoderrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#<'static> { |
| 269 | /// Creates a new encoder. |
| 270 | pub fn newrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'static>`]new().(level: i32) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'static>`]> { |
| 271 | Selfrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'static>`]::with_dictionaryrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'static>`]with_dictionary().(level, &[]) |
| 272 | } |
| 273 | |
| 274 | /// Creates a new encoder initialized with the given dictionary. |
| 275 | pub fn with_dictionaryrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'static>`]with_dictionary().(level: i32, dictionary: &[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'static>`]> { |
| 276 | let mut context = zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::CCtxrust-analyzer cargo zstd-safe 7.2.2 CCtx#::createrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]create().(); |
| 277 | |
| 278 | context |
| 279 | .set_parameterrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]set_parameter().(CParameterrust-analyzer cargo zstd-safe 7.2.2 CParameter#::CompressionLevelrust-analyzer cargo zstd-safe 7.2.2 CParameter#CompressionLevel#(level)) |
| 280 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 281 | |
| 282 | context |
| 283 | .load_dictionaryrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]load_dictionary().(dictionary) |
| 284 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 285 | |
| 286 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Encoderrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder# { |
| 287 | contextrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#context.: MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#::Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Owned#(context), |
| 288 | }) |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | impl<'a> Encoderrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#<'a> { |
| 293 | /// Creates a new encoder that uses the provided context for serialization. |
| 294 | pub fn with_contextrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`]with_context().(context: &'a mut zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::CCtxrust-analyzer cargo zstd-safe 7.2.2 CCtx#<'static>) -> Selfrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`] { |
| 295 | Selfrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`] { |
| 296 | contextrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#context.: MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#::Borrowedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Borrowed#(context), |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | /// Creates a new encoder using an existing `EncoderDictionary`. |
| 301 | pub fn with_prepared_dictionaryrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`]with_prepared_dictionary().<'b>( |
| 302 | dictionary: &EncoderDictionaryrust-analyzer cargo zstd 0.13.3 dict/EncoderDictionary#<'b>, |
| 303 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`]> |
| 304 | where |
| 305 | 'b: 'a, |
| 306 | { |
| 307 | let mut context = zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::CCtxrust-analyzer cargo zstd-safe 7.2.2 CCtx#::createrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]create().(); |
| 308 | context |
| 309 | .ref_cdictrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]ref_cdict().(dictionary.as_cdictrust-analyzer cargo zstd 0.13.3 dict/impl#[`EncoderDictionary<'a>`]as_cdict().()) |
| 310 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 311 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Encoderrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder# { |
| 312 | contextrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#context.: MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#::Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Owned#(context), |
| 313 | }) |
| 314 | } |
| 315 | |
| 316 | /// Creates a new encoder initialized with the given ref prefix. |
| 317 | pub fn with_ref_prefixrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`]with_ref_prefix().<'b>( |
| 318 | level: i32, |
| 319 | ref_prefix: &'b [u8], |
| 320 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`]> |
| 321 | where |
| 322 | 'b: 'a, |
| 323 | { |
| 324 | let mut context = zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::CCtxrust-analyzer cargo zstd-safe 7.2.2 CCtx#::createrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]create().(); |
| 325 | |
| 326 | context |
| 327 | .set_parameterrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]set_parameter().(CParameterrust-analyzer cargo zstd-safe 7.2.2 CParameter#::CompressionLevelrust-analyzer cargo zstd-safe 7.2.2 CParameter#CompressionLevel#(level)) |
| 328 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 329 | |
| 330 | context.ref_prefixrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]ref_prefix().(ref_prefix).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 331 | |
| 332 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Encoderrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder# { |
| 333 | contextrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#context.: MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#::Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Owned#(context), |
| 334 | }) |
| 335 | } |
| 336 | |
| 337 | /// Sets a compression parameter for this encoder. |
| 338 | pub fn set_parameterrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`]set_parameter().(&mut self, parameter: CParameterrust-analyzer cargo zstd-safe 7.2.2 CParameter#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 339 | match &mut self.contextrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#context. { |
| 340 | MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#::Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Owned#(x) => x.set_parameterrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]set_parameter().(parameter), |
| 341 | MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#::Borrowedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Borrowed#(x) => x.set_parameterrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]set_parameter().(parameter), |
| 342 | } |
| 343 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 344 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 345 | } |
| 346 | |
| 347 | /// Sets the size of the input expected by zstd. |
| 348 | /// |
| 349 | /// May affect compression ratio. |
| 350 | /// |
| 351 | /// It is an error to give an incorrect size (an error _will_ be returned when closing the |
| 352 | /// stream). |
| 353 | /// |
| 354 | /// If `None` is given, it assume the size is not known (default behaviour). |
| 355 | pub fn set_pledged_src_sizerust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`]set_pledged_src_size().( |
| 356 | &mut self, |
| 357 | pledged_src_size: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u64>, |
| 358 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 359 | match &mut self.contextrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#context. { |
| 360 | MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#::Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Owned#(x) => { |
| 361 | x.set_pledged_src_sizerust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]set_pledged_src_size().(pledged_src_size) |
| 362 | } |
| 363 | MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#::Borrowedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Borrowed#(x) => { |
| 364 | x.set_pledged_src_sizerust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]set_pledged_src_size().(pledged_src_size) |
| 365 | } |
| 366 | } |
| 367 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 368 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | impl<'a> Operationrust-analyzer cargo zstd 0.13.3 stream/raw/Operation# for Encoderrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#<'a> { |
| 373 | fn runrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`][Operation]run().<C: WriteBufrust-analyzer cargo zstd-safe 7.2.2 WriteBuf# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>( |
| 374 | &mut self, |
| 375 | input: &mut InBufferrust-analyzer cargo zstd-safe 7.2.2 InBuffer#<'_>, |
| 376 | output: &mut OutBufferrust-analyzer cargo zstd-safe 7.2.2 OutBuffer#<'_, C>, |
| 377 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> { |
| 378 | match &mut self.contextrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#context. { |
| 379 | MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#::Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Owned#(x) => x.compress_streamrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]compress_stream().(output, input), |
| 380 | MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#::Borrowedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Borrowed#(x) => x.compress_streamrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]compress_stream().(output, input), |
| 381 | } |
| 382 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().) |
| 383 | } |
| 384 | |
| 385 | fn flushrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`][Operation]flush().<C: WriteBufrust-analyzer cargo zstd-safe 7.2.2 WriteBuf# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>( |
| 386 | &mut self, |
| 387 | output: &mut OutBufferrust-analyzer cargo zstd-safe 7.2.2 OutBuffer#<'_, C>, |
| 388 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> { |
| 389 | match &mut self.contextrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#context. { |
| 390 | MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#::Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Owned#(x) => x.flush_streamrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]flush_stream().(output), |
| 391 | MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#::Borrowedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Borrowed#(x) => x.flush_streamrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]flush_stream().(output), |
| 392 | } |
| 393 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().) |
| 394 | } |
| 395 | |
| 396 | fn finishrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`][Operation]finish().<C: WriteBufrust-analyzer cargo zstd-safe 7.2.2 WriteBuf# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>( |
| 397 | &mut self, |
| 398 | output: &mut OutBufferrust-analyzer cargo zstd-safe 7.2.2 OutBuffer#<'_, C>, |
| 399 | _finished_frame: bool, |
| 400 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> { |
| 401 | match &mut self.contextrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#context. { |
| 402 | MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#::Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Owned#(x) => x.end_streamrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]end_stream().(output), |
| 403 | MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#::Borrowedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Borrowed#(x) => x.end_streamrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]end_stream().(output), |
| 404 | } |
| 405 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().) |
| 406 | } |
| 407 | |
| 408 | fn reinitrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`][Operation]reinit().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 409 | match &mut self.contextrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#context. { |
| 410 | MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#::Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Owned#(x) => { |
| 411 | x.resetrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]reset().(zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::ResetDirectiverust-analyzer cargo zstd-safe 7.2.2 ResetDirective#::SessionOnlyrust-analyzer cargo zstd-safe 7.2.2 ResetDirective#SessionOnly#) |
| 412 | } |
| 413 | MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#::Borrowedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Borrowed#(x) => { |
| 414 | x.resetrust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]reset().(zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::ResetDirectiverust-analyzer cargo zstd-safe 7.2.2 ResetDirective#::SessionOnlyrust-analyzer cargo zstd-safe 7.2.2 ResetDirective#SessionOnly#) |
| 415 | } |
| 416 | } |
| 417 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(map_error_coderust-analyzer cargo zstd 0.13.3 map_error_code().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 418 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | enum MaybeOwnedCCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#<'a> { |
| 423 | Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Owned#(zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::CCtxrust-analyzer cargo zstd-safe 7.2.2 CCtx#<'a>), |
| 424 | Borrowedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedCCtx#Borrowed#(&'a mut zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::CCtxrust-analyzer cargo zstd-safe 7.2.2 CCtx#<'static>), |
| 425 | } |
| 426 | |
| 427 | enum MaybeOwnedDCtxrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#<'a> { |
| 428 | Ownedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#Owned#(zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::DCtxrust-analyzer cargo zstd-safe 7.2.2 DCtx#<'a>), |
| 429 | Borrowedrust-analyzer cargo zstd 0.13.3 stream/raw/MaybeOwnedDCtx#Borrowed#(&'a mut zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::DCtxrust-analyzer cargo zstd-safe 7.2.2 DCtx#<'static>), |
| 430 | } |
| 431 | |
| 432 | #[cfg(test)] |
| 433 | mod testsrust-analyzer cargo zstd 0.13.3 stream/raw/tests/ { |
| 434 | |
| 435 | // This requires impl for [u8; N] which is currently behind a feature. |
| 436 | #[cfg(feature = "arrays")] |
| 437 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 438 | fn test_cyclerust-analyzer cargo zstd 0.13.3 stream/raw/tests/test_cycle().() { |
| 439 | use superrust-analyzer cargo zstd 0.13.3 stream/raw/::{Decoderrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#, Encoderrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#, InBufferrust-analyzer cargo zstd-safe 7.2.2 InBuffer#, Operationrust-analyzer cargo zstd 0.13.3 stream/raw/Operation#, OutBufferrust-analyzer cargo zstd-safe 7.2.2 OutBuffer#}; |
| 440 | |
| 441 | let mut encoder = Encoderrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#::newrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'static>`]new().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 442 | let mut decoder = Decoderrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#::newrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'static>`]new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 443 | |
| 444 | // Step 1: compress |
| 445 | let mut input = InBufferrust-analyzer cargo zstd-safe 7.2.2 InBuffer#::aroundrust-analyzer cargo zstd-safe 7.2.2 impl#[`InBuffer<'a>`]around().(b"AbcdefAbcdefabcdef"); |
| 446 | |
| 447 | let mut output = [0u8; 128]; |
| 448 | let mut output = OutBufferrust-analyzer cargo zstd-safe 7.2.2 OutBuffer#::aroundrust-analyzer cargo zstd-safe 7.2.2 impl#[`OutBuffer<'a, C>`]around().(&mut output); |
| 449 | |
| 450 | loop { |
| 451 | encoder.runrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`][Operation]run().(&mut input, &mut output).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 452 | |
| 453 | if input.posrust-analyzer cargo zstd-safe 7.2.2 InBuffer#pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().input.srcrust-analyzer cargo zstd-safe 7.2.2 InBuffer#src..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 454 | break; |
| 455 | } |
| 456 | } |
| 457 | encoder.finishrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`][Operation]finish().(&mut output, true).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 458 | |
| 459 | let initial_data = input.srcrust-analyzer cargo zstd-safe 7.2.2 InBuffer#src.; |
| 460 | |
| 461 | // Step 2: decompress |
| 462 | let mut input = InBufferrust-analyzer cargo zstd-safe 7.2.2 InBuffer#::aroundrust-analyzer cargo zstd-safe 7.2.2 impl#[`InBuffer<'a>`]around().(output.as_slicerust-analyzer cargo zstd-safe 7.2.2 impl#[`OutBuffer<'a, C>`]as_slice().()); |
| 463 | let mut output = [0u8; 128]; |
| 464 | let mut output = OutBufferrust-analyzer cargo zstd-safe 7.2.2 OutBuffer#::aroundrust-analyzer cargo zstd-safe 7.2.2 impl#[`OutBuffer<'a, C>`]around().(&mut output); |
| 465 | |
| 466 | loop { |
| 467 | decoder.runrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'_>`][Operation]run().(&mut input, &mut output).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 468 | |
| 469 | if input.posrust-analyzer cargo zstd-safe 7.2.2 InBuffer#pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().input.srcrust-analyzer cargo zstd-safe 7.2.2 InBuffer#src..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 470 | break; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(initial_data, output.as_slicerust-analyzer cargo zstd-safe 7.2.2 impl#[`OutBuffer<'a, C>`]as_slice().()); |
| 475 | } |
| 476 | } |