| 1 | //! Implement push-based [`Write`] trait for both compressing and decompressing. |
| 2 | 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/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}; |
| 3 | |
| 4 | use zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/; |
| 5 | |
| 6 | 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#}; |
| 7 | use craterust-analyzer cargo zstd 0.13.3 crate/::streamrust-analyzer cargo zstd 0.13.3 stream/::{rawrust-analyzer cargo zstd 0.13.3 stream/raw/, ziorust-analyzer cargo zstd 0.13.3 stream/zio/}; |
| 8 | |
| 9 | #[cfg(test)] |
| 10 | mod testsrust-analyzer cargo zstd 0.13.3 stream/write/tests/; |
| 11 | |
| 12 | /// An encoder that compress and forward data to another writer. |
| 13 | /// |
| 14 | /// This allows to compress a stream of data |
| 15 | /// (good for files or heavy network stream). |
| 16 | /// |
| 17 | /// Don't forget to call [`finish()`] before dropping it! |
| 18 | /// |
| 19 | /// Alternatively, you can call [`auto_finish()`] to use an |
| 20 | /// [`AutoFinishEncoder`] that will finish on drop. |
| 21 | /// |
| 22 | /// Note: The zstd library has its own internal input buffer (~128kb). |
| 23 | /// |
| 24 | /// [`finish()`]: #method.finish |
| 25 | /// [`auto_finish()`]: #method.auto_finish |
| 26 | /// [`AutoFinishEncoder`]: AutoFinishEncoder |
| 27 | pub struct Encoderrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#<'a, W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> { |
| 28 | // output writer (compressed data) |
| 29 | writerrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#writer.: ziorust-analyzer cargo zstd 0.13.3 stream/zio/::Writerrust-analyzer cargo zstd 0.13.3 stream/zio/writer/Writer#<W, rawrust-analyzer cargo zstd 0.13.3 stream/raw/::Encoderrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#<'a>>, |
| 30 | } |
| 31 | |
| 32 | /// A decoder that decompress and forward data to another writer. |
| 33 | /// |
| 34 | /// Note that you probably want to `flush()` after writing your stream content. |
| 35 | /// You can use [`auto_flush()`] to automatically flush the writer on drop. |
| 36 | /// |
| 37 | /// [`auto_flush()`]: Decoder::auto_flush |
| 38 | pub struct Decoderrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#<'a, W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> { |
| 39 | // output writer (decompressed data) |
| 40 | writerrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#writer.: ziorust-analyzer cargo zstd 0.13.3 stream/zio/::Writerrust-analyzer cargo zstd 0.13.3 stream/zio/writer/Writer#<W, rawrust-analyzer cargo zstd 0.13.3 stream/raw/::Decoderrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#<'a>>, |
| 41 | } |
| 42 | |
| 43 | /// A wrapper around an `Encoder<W>` that finishes the stream on drop. |
| 44 | /// |
| 45 | /// This can be created by the [`auto_finish()`] method on the [`Encoder`]. |
| 46 | /// |
| 47 | /// [`auto_finish()`]: Encoder::auto_finish |
| 48 | /// [`Encoder`]: Encoder |
| 49 | pub struct AutoFinishEncoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#< |
| 50 | 'a, |
| 51 | W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, |
| 52 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(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#<W>) = Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(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#<W>)>, |
| 53 | > { |
| 54 | // We wrap this in an option to take it during drop. |
| 55 | encoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#encoder.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Encoderrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#<'a, W>>, |
| 56 | |
| 57 | on_finishrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#on_finish.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<F>, |
| 58 | } |
| 59 | |
| 60 | /// A wrapper around a `Decoder<W>` that flushes the stream on drop. |
| 61 | /// |
| 62 | /// This can be created by the [`auto_flush()`] method on the [`Decoder`]. |
| 63 | /// |
| 64 | /// [`auto_flush()`]: Decoder::auto_flush |
| 65 | /// [`Decoder`]: Decoder |
| 66 | pub struct AutoFlushDecoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#< |
| 67 | 'a, |
| 68 | W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, |
| 69 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(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#<()>) = Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(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#<()>)>, |
| 70 | > { |
| 71 | // We wrap this in an option to take it during drop. |
| 72 | decoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#decoder.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Decoderrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#<'a, W>>, |
| 73 | |
| 74 | on_flushrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#on_flush.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<F>, |
| 75 | } |
| 76 | |
| 77 | impl<'a, W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(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#<()>)> AutoFlushDecoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#<'a, W, F> { |
| 78 | fn newrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`AutoFlushDecoder<'a, W, F>`]new().(decoder: Decoderrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#<'a, W>, on_flush: F) -> Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`AutoFlushDecoder<'a, W, F>`] { |
| 79 | AutoFlushDecoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder# { |
| 80 | decoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#decoder.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(decoder), |
| 81 | on_flushrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#on_flush.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(on_flush), |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /// Acquires a reference to the underlying writer. |
| 86 | pub fn get_refrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`AutoFlushDecoder<'a, W, F>`]get_ref().(&self) -> &W { |
| 87 | self.decoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#decoder..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().get_refrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`]get_ref().() |
| 88 | } |
| 89 | |
| 90 | /// Acquires a mutable reference to the underlying writer. |
| 91 | /// |
| 92 | /// Note that mutation of the writer may result in surprising results if |
| 93 | /// this decoder is continued to be used. |
| 94 | /// |
| 95 | /// Mostly used for testing purposes. |
| 96 | pub fn get_mutrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`AutoFlushDecoder<'a, W, F>`]get_mut().(&mut self) -> &mut W { |
| 97 | self.decoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#decoder..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().get_mutrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`]get_mut().() |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | impl<W, F> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for AutoFlushDecoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#<'_, W, F> |
| 102 | where |
| 103 | W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, |
| 104 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(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#<()>), |
| 105 | { |
| 106 | fn droprust-analyzer cargo zstd 0.13.3 stream/write/impl#[`AutoFlushDecoder<'_, W, F>`][Drop]drop().(&mut self) { |
| 107 | let mut decoder = self.decoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#decoder..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 108 | let result = decoder.flushrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'_, W>`][Write]flush().(); |
| 109 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut on_finish) = self.on_flushrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#on_flush..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() { |
| 110 | on_finish(result); |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(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#<()>)> Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# for AutoFlushDecoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#<'_, W, F> { |
| 116 | fn writerust-analyzer cargo zstd 0.13.3 stream/write/impl#[`AutoFlushDecoder<'_, W, F>`][Write]write().(&mut self, buf: &[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#<usize> { |
| 117 | self.decoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#decoder..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().writerust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'_, W>`][Write]write().(buf) |
| 118 | } |
| 119 | |
| 120 | fn flushrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`AutoFlushDecoder<'_, W, F>`][Write]flush().(&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#<()> { |
| 121 | self.decoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#decoder..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().flushrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'_, W>`][Write]flush().() |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | impl<'a, W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(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#<W>)> AutoFinishEncoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#<'a, W, F> { |
| 126 | fn newrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`AutoFinishEncoder<'a, W, F>`]new().(encoder: Encoderrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#<'a, W>, on_finish: F) -> Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`AutoFinishEncoder<'a, W, F>`] { |
| 127 | AutoFinishEncoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder# { |
| 128 | encoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#encoder.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(encoder), |
| 129 | on_finishrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#on_finish.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(on_finish), |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /// Acquires a reference to the underlying writer. |
| 134 | pub fn get_refrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`AutoFinishEncoder<'a, W, F>`]get_ref().(&self) -> &W { |
| 135 | self.encoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#encoder..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().get_refrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]get_ref().() |
| 136 | } |
| 137 | |
| 138 | /// Acquires a mutable reference to the underlying writer. |
| 139 | /// |
| 140 | /// Note that mutation of the writer may result in surprising results if |
| 141 | /// this encoder is continued to be used. |
| 142 | /// |
| 143 | /// Mostly used for testing purposes. |
| 144 | pub fn get_mutrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`AutoFinishEncoder<'a, W, F>`]get_mut().(&mut self) -> &mut W { |
| 145 | self.encoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#encoder..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().get_mutrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]get_mut().() |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(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#<W>)> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for AutoFinishEncoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#<'_, W, F> { |
| 150 | fn droprust-analyzer cargo zstd 0.13.3 stream/write/impl#[`AutoFinishEncoder<'_, W, F>`][Drop]drop().(&mut self) { |
| 151 | let result = self.encoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#encoder..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().finishrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]finish().(); |
| 152 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut on_finish) = self.on_finishrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#on_finish..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() { |
| 153 | on_finish(result); |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(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#<W>)> Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# for AutoFinishEncoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#<'_, W, F> { |
| 159 | fn writerust-analyzer cargo zstd 0.13.3 stream/write/impl#[`AutoFinishEncoder<'_, W, F>`][Write]write().(&mut self, buf: &[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#<usize> { |
| 160 | self.encoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#encoder..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().writerust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`][Write]write().(buf) |
| 161 | } |
| 162 | |
| 163 | fn flushrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`AutoFinishEncoder<'_, W, F>`][Write]flush().(&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#<()> { |
| 164 | self.encoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#encoder..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().flushrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`][Write]flush().() |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> Encoderrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#<'static, W> { |
| 169 | /// Creates a new encoder. |
| 170 | /// |
| 171 | /// `level`: compression level (1-22). |
| 172 | /// |
| 173 | /// A level of `0` uses zstd's default (currently `3`). |
| 174 | pub fn newrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'static, W>`]new().(writer: W, 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/write/impl#[`Encoder<'static, W>`]> { |
| 175 | Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'static, W>`]::with_dictionaryrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'static, W>`]with_dictionary().(writer, level, &[]) |
| 176 | } |
| 177 | |
| 178 | /// Creates a new encoder, using an existing dictionary. |
| 179 | /// |
| 180 | /// (Provides better compression ratio for small files, |
| 181 | /// but requires the dictionary to be present during decompression.) |
| 182 | /// |
| 183 | /// A level of `0` uses zstd's default (currently `3`). |
| 184 | pub fn with_dictionaryrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'static, W>`]with_dictionary().( |
| 185 | writer: W, |
| 186 | level: i32, |
| 187 | dictionary: &[u8], |
| 188 | ) -> 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/write/impl#[`Encoder<'static, W>`]> { |
| 189 | let encoder = rawrust-analyzer cargo zstd 0.13.3 stream/raw/::Encoderrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#::with_dictionaryrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'static>`]with_dictionary().(level, dictionary)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 190 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'static, W>`]::with_encoderrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]with_encoder().(writer, encoder)) |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | impl<'a, W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> Encoderrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#<'a, W> { |
| 195 | /// Creates a new encoder from a prepared zio writer. |
| 196 | pub fn with_writerrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]with_writer().(writer: ziorust-analyzer cargo zstd 0.13.3 stream/zio/::Writerrust-analyzer cargo zstd 0.13.3 stream/zio/writer/Writer#<W, rawrust-analyzer cargo zstd 0.13.3 stream/raw/::Encoderrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#<'a>>) -> Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`] { |
| 197 | Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`] { writerrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#writer. } |
| 198 | } |
| 199 | |
| 200 | /// Creates a new encoder from the given `Write` and raw encoder. |
| 201 | pub fn with_encoderrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]with_encoder().(writer: W, encoder: rawrust-analyzer cargo zstd 0.13.3 stream/raw/::Encoderrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#<'a>) -> Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`] { |
| 202 | let writer = ziorust-analyzer cargo zstd 0.13.3 stream/zio/::Writerrust-analyzer cargo zstd 0.13.3 stream/zio/writer/Writer#::newrust-analyzer cargo zstd 0.13.3 stream/zio/writer/impl#[`Writer<W, D>`]new().(writer, encoder); |
| 203 | Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]::with_writerrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]with_writer().(writer) |
| 204 | } |
| 205 | |
| 206 | /// Creates an encoder that uses the provided context to compress a stream. |
| 207 | pub fn with_contextrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]with_context().( |
| 208 | writer: W, |
| 209 | context: &'a mut zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::CCtxrust-analyzer cargo zstd-safe 7.2.2 CCtx#<'static>, |
| 210 | ) -> Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`] { |
| 211 | let encoder = rawrust-analyzer cargo zstd 0.13.3 stream/raw/::Encoderrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#::with_contextrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`]with_context().(context); |
| 212 | Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]::with_encoderrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]with_encoder().(writer, encoder) |
| 213 | } |
| 214 | |
| 215 | /// Creates a new encoder, using an existing prepared `EncoderDictionary`. |
| 216 | /// |
| 217 | /// (Provides better compression ratio for small files, |
| 218 | /// but requires the dictionary to be present during decompression.) |
| 219 | pub fn with_prepared_dictionaryrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]with_prepared_dictionary().<'b>( |
| 220 | writer: W, |
| 221 | dictionary: &EncoderDictionaryrust-analyzer cargo zstd 0.13.3 dict/EncoderDictionary#<'b>, |
| 222 | ) -> 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/write/impl#[`Encoder<'a, W>`]> |
| 223 | where |
| 224 | 'b: 'a, |
| 225 | { |
| 226 | let encoder = rawrust-analyzer cargo zstd 0.13.3 stream/raw/::Encoderrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#::with_prepared_dictionaryrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`]with_prepared_dictionary().(dictionary)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 227 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]::with_encoderrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]with_encoder().(writer, encoder)) |
| 228 | } |
| 229 | |
| 230 | /// Creates a new encoder, using a ref prefix |
| 231 | pub fn with_ref_prefixrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]with_ref_prefix().<'b>( |
| 232 | writer: W, |
| 233 | level: i32, |
| 234 | ref_prefix: &'b [u8], |
| 235 | ) -> 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/write/impl#[`Encoder<'a, W>`]> |
| 236 | where |
| 237 | 'b: 'a, |
| 238 | { |
| 239 | let encoder = rawrust-analyzer cargo zstd 0.13.3 stream/raw/::Encoderrust-analyzer cargo zstd 0.13.3 stream/raw/Encoder#::with_ref_prefixrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Encoder<'a>`]with_ref_prefix().(level, ref_prefix)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 240 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]::with_encoderrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]with_encoder().(writer, encoder)) |
| 241 | } |
| 242 | |
| 243 | /// Returns a wrapper around `self` that will finish the stream on drop. |
| 244 | pub fn auto_finishrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]auto_finish().(self) -> AutoFinishEncoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#<'a, W> { |
| 245 | AutoFinishEncoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder# { |
| 246 | encoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#encoder.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self), |
| 247 | on_finishrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#on_finish.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | /// Returns an encoder that will finish the stream on drop. |
| 252 | /// |
| 253 | /// Calls the given callback with the result from `finish()`. This runs during drop so it's |
| 254 | /// important that the provided callback doesn't panic. |
| 255 | pub fn on_finishrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]on_finish().<F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(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#<W>)>( |
| 256 | self, |
| 257 | f: F, |
| 258 | ) -> AutoFinishEncoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#<'a, W, F> { |
| 259 | AutoFinishEncoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFinishEncoder#::newrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`AutoFinishEncoder<'a, W, F>`]new().(self, f) |
| 260 | } |
| 261 | |
| 262 | /// Acquires a reference to the underlying writer. |
| 263 | pub fn get_refrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]get_ref().(&self) -> &W { |
| 264 | self.writerrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#writer..writerrust-analyzer cargo zstd 0.13.3 stream/zio/writer/impl#[`Writer<W, D>`]writer().() |
| 265 | } |
| 266 | |
| 267 | /// Acquires a mutable reference to the underlying writer. |
| 268 | /// |
| 269 | /// Note that mutation of the writer may result in surprising results if |
| 270 | /// this encoder is continued to be used. |
| 271 | pub fn get_mutrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]get_mut().(&mut self) -> &mut W { |
| 272 | self.writerrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#writer..writer_mutrust-analyzer cargo zstd 0.13.3 stream/zio/writer/impl#[`Writer<W, D>`]writer_mut().() |
| 273 | } |
| 274 | |
| 275 | /// **Required**: Finishes the stream. |
| 276 | /// |
| 277 | /// You *need* to finish the stream when you're done writing, either with |
| 278 | /// this method or with [`try_finish(self)`](#method.try_finish). |
| 279 | /// |
| 280 | /// This returns the inner writer in case you need it. |
| 281 | /// |
| 282 | /// To get back `self` in case an error happened, use `try_finish`. |
| 283 | /// |
| 284 | /// **Note**: If you don't want (or can't) call `finish()` manually after |
| 285 | /// writing your data, consider using `auto_finish()` to get an |
| 286 | /// `AutoFinishEncoder`. |
| 287 | pub fn finishrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]finish().(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#<W> { |
| 288 | self.try_finishrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]try_finish().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|(_, err)| err) |
| 289 | } |
| 290 | |
| 291 | /// **Required**: Attempts to finish the stream. |
| 292 | /// |
| 293 | /// You *need* to finish the stream when you're done writing, either with |
| 294 | /// this method or with [`finish(self)`](#method.finish). |
| 295 | /// |
| 296 | /// This returns the inner writer if the finish was successful, or the |
| 297 | /// object plus an error if it wasn't. |
| 298 | /// |
| 299 | /// `write` on this object will panic after `try_finish` has been called, |
| 300 | /// even if it fails. |
| 301 | pub fn try_finishrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]try_finish().(mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<W, (Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`], 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#)> { |
| 302 | match self.writerrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#writer..finishrust-analyzer cargo zstd 0.13.3 stream/zio/writer/impl#[`Writer<W, D>`]finish().() { |
| 303 | // Return the writer, because why not |
| 304 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.writerrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#writer..into_innerrust-analyzer cargo zstd 0.13.3 stream/zio/writer/impl#[`Writer<W, D>`]into_inner().().0), |
| 305 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#((self, e)), |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /// Attempts to finish the stream. |
| 310 | /// |
| 311 | /// You *need* to finish the stream when you're done writing, either with |
| 312 | /// this method or with [`finish(self)`](#method.finish). |
| 313 | pub fn do_finishrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]do_finish().(&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#<()> { |
| 314 | self.writerrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#writer..finishrust-analyzer cargo zstd 0.13.3 stream/zio/writer/impl#[`Writer<W, D>`]finish().() |
| 315 | } |
| 316 | |
| 317 | /// Return a recommendation for the size of data to write at once. |
| 318 | pub fn recommended_input_sizerust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]recommended_input_size().() -> usize { |
| 319 | zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::CCtxrust-analyzer cargo zstd-safe 7.2.2 CCtx#::in_sizerust-analyzer cargo zstd-safe 7.2.2 impl#[`CCtx<'a>`]in_size().() |
| 320 | } |
| 321 | |
| 322 | craterust-analyzer cargo zstd 0.13.3 crate/::encoder_commonrust-analyzer cargo zstd 0.13.3 stream/encoder_common!!(writerrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#writer.); |
| 323 | } |
| 324 | |
| 325 | impl<'a, W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# for Encoderrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#<'a, W> { |
| 326 | fn writerust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`][Write]write().(&mut self, buf: &[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#<usize> { |
| 327 | self.writerrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#writer..writerust-analyzer cargo zstd 0.13.3 stream/zio/writer/impl#[`Writer<W, D>`][Write]write().(buf) |
| 328 | } |
| 329 | |
| 330 | fn flushrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`][Write]flush().(&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#<()> { |
| 331 | self.writerrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#writer..flushrust-analyzer cargo zstd 0.13.3 stream/zio/writer/impl#[`Writer<W, D>`][Write]flush().() |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> Decoderrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#<'static, W> { |
| 336 | /// Creates a new decoder. |
| 337 | pub fn newrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'static, W>`]new().(writer: W) -> 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/write/impl#[`Decoder<'static, W>`]> { |
| 338 | Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'static, W>`]::with_dictionaryrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'static, W>`]with_dictionary().(writer, &[]) |
| 339 | } |
| 340 | |
| 341 | /// Creates a new decoder, using an existing dictionary. |
| 342 | /// |
| 343 | /// (Provides better compression ratio for small files, |
| 344 | /// but requires the dictionary to be present during decompression.) |
| 345 | pub fn with_dictionaryrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'static, W>`]with_dictionary().(writer: W, 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/write/impl#[`Decoder<'static, W>`]> { |
| 346 | let decoder = rawrust-analyzer cargo zstd 0.13.3 stream/raw/::Decoderrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#::with_dictionaryrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'static>`]with_dictionary().(dictionary)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 347 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'static, W>`]::with_decoderrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`]with_decoder().(writer, decoder)) |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | impl<'a, W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> Decoderrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#<'a, W> { |
| 352 | /// Creates a new decoder around the given prepared zio writer. |
| 353 | /// |
| 354 | /// # Examples |
| 355 | /// |
| 356 | /// ```rust |
| 357 | /// fn wrap<W: std::io::Write>(writer: W) -> zstd::stream::write::Decoder<'static, W> { |
| 358 | /// let decoder = zstd::stream::raw::Decoder::new().unwrap(); |
| 359 | /// let writer = zstd::stream::zio::Writer::new(writer, decoder); |
| 360 | /// zstd::stream::write::Decoder::with_writer(writer) |
| 361 | /// } |
| 362 | /// ``` |
| 363 | pub fn with_writerrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`]with_writer().(writer: ziorust-analyzer cargo zstd 0.13.3 stream/zio/::Writerrust-analyzer cargo zstd 0.13.3 stream/zio/writer/Writer#<W, rawrust-analyzer cargo zstd 0.13.3 stream/raw/::Decoderrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#<'a>>) -> Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`] { |
| 364 | Decoderrust-analyzer cargo zstd 0.13.3 stream/write/Decoder# { writerrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#writer. } |
| 365 | } |
| 366 | |
| 367 | /// Creates a new decoder around the given `Write` and raw decoder. |
| 368 | pub fn with_decoderrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`]with_decoder().(writer: W, decoder: rawrust-analyzer cargo zstd 0.13.3 stream/raw/::Decoderrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#<'a>) -> Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`] { |
| 369 | let writer = ziorust-analyzer cargo zstd 0.13.3 stream/zio/::Writerrust-analyzer cargo zstd 0.13.3 stream/zio/writer/Writer#::newrust-analyzer cargo zstd 0.13.3 stream/zio/writer/impl#[`Writer<W, D>`]new().(writer, decoder); |
| 370 | Decoderrust-analyzer cargo zstd 0.13.3 stream/write/Decoder# { writerrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#writer. } |
| 371 | } |
| 372 | |
| 373 | /// Creates a new decoder, using an existing prepared `DecoderDictionary`. |
| 374 | /// |
| 375 | /// (Provides better compression ratio for small files, |
| 376 | /// but requires the dictionary to be present during decompression.) |
| 377 | pub fn with_prepared_dictionaryrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`]with_prepared_dictionary().<'b>( |
| 378 | writer: W, |
| 379 | dictionary: &DecoderDictionaryrust-analyzer cargo zstd 0.13.3 dict/DecoderDictionary#<'b>, |
| 380 | ) -> 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/write/impl#[`Decoder<'a, W>`]> |
| 381 | where |
| 382 | 'b: 'a, |
| 383 | { |
| 384 | let decoder = rawrust-analyzer cargo zstd 0.13.3 stream/raw/::Decoderrust-analyzer cargo zstd 0.13.3 stream/raw/Decoder#::with_prepared_dictionaryrust-analyzer cargo zstd 0.13.3 stream/raw/impl#[`Decoder<'a>`]with_prepared_dictionary().(dictionary)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 385 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`]::with_decoderrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`]with_decoder().(writer, decoder)) |
| 386 | } |
| 387 | |
| 388 | /// Acquires a reference to the underlying writer. |
| 389 | pub fn get_refrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`]get_ref().(&self) -> &W { |
| 390 | self.writerrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#writer..writerrust-analyzer cargo zstd 0.13.3 stream/zio/writer/impl#[`Writer<W, D>`]writer().() |
| 391 | } |
| 392 | |
| 393 | /// Acquires a mutable reference to the underlying writer. |
| 394 | /// |
| 395 | /// Note that mutation of the writer may result in surprising results if |
| 396 | /// this decoder is continued to be used. |
| 397 | pub fn get_mutrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`]get_mut().(&mut self) -> &mut W { |
| 398 | self.writerrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#writer..writer_mutrust-analyzer cargo zstd 0.13.3 stream/zio/writer/impl#[`Writer<W, D>`]writer_mut().() |
| 399 | } |
| 400 | |
| 401 | /// Returns the inner `Write`. |
| 402 | pub fn into_innerrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`]into_inner().(self) -> W { |
| 403 | self.writerrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#writer..into_innerrust-analyzer cargo zstd 0.13.3 stream/zio/writer/impl#[`Writer<W, D>`]into_inner().().0 |
| 404 | } |
| 405 | |
| 406 | /// Return a recommendation for the size of data to write at once. |
| 407 | pub fn recommended_input_sizerust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`]recommended_input_size().() -> usize { |
| 408 | zstd_saferust-analyzer cargo zstd-safe 7.2.2 crate/::DCtxrust-analyzer cargo zstd-safe 7.2.2 DCtx#::in_sizerust-analyzer cargo zstd-safe 7.2.2 impl#[`DCtx<'a>`]in_size().() |
| 409 | } |
| 410 | |
| 411 | /// Returns a wrapper around `self` that will flush the stream on drop. |
| 412 | pub fn auto_flushrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`]auto_flush().(self) -> AutoFlushDecoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#<'a, W> { |
| 413 | AutoFlushDecoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder# { |
| 414 | decoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#decoder.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self), |
| 415 | on_flushrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#on_flush.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | /// Returns a decoder that will flush the stream on drop. |
| 420 | /// |
| 421 | /// Calls the given callback with the result from `flush()`. This runs during drop so it's |
| 422 | /// important that the provided callback doesn't panic. |
| 423 | pub fn on_flushrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`]on_flush().<F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(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#<()>)>( |
| 424 | self, |
| 425 | f: F, |
| 426 | ) -> AutoFlushDecoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#<'a, W, F> { |
| 427 | AutoFlushDecoderrust-analyzer cargo zstd 0.13.3 stream/write/AutoFlushDecoder#::newrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`AutoFlushDecoder<'a, W, F>`]new().(self, f) |
| 428 | } |
| 429 | |
| 430 | craterust-analyzer cargo zstd 0.13.3 crate/::decoder_commonrust-analyzer cargo zstd 0.13.3 stream/decoder_common!!(writerrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#writer.); |
| 431 | } |
| 432 | |
| 433 | impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# for Decoderrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#<'_, W> { |
| 434 | fn writerust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'_, W>`][Write]write().(&mut self, buf: &[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#<usize> { |
| 435 | self.writerrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#writer..writerust-analyzer cargo zstd 0.13.3 stream/zio/writer/impl#[`Writer<W, D>`][Write]write().(buf) |
| 436 | } |
| 437 | |
| 438 | fn flushrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'_, W>`][Write]flush().(&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#<()> { |
| 439 | self.writerrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#writer..flushrust-analyzer cargo zstd 0.13.3 stream/zio/writer/impl#[`Writer<W, D>`][Write]flush().() |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | fn _assert_traitsrust-analyzer cargo zstd 0.13.3 stream/write/_assert_traits().() { |
| 444 | fn _assert_sendrust-analyzer cargo zstd 0.13.3 stream/write/_assert_send().<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>(_: T) {} |
| 445 | |
| 446 | _assert_sendrust-analyzer cargo zstd 0.13.3 stream/write/_assert_send().(Decoderrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#::newrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'static, W>`]new().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().())); |
| 447 | _assert_sendrust-analyzer cargo zstd 0.13.3 stream/write/_assert_send().(Encoderrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#::newrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'static, W>`]new().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), 1)); |
| 448 | _assert_sendrust-analyzer cargo zstd 0.13.3 stream/write/_assert_send().(Decoderrust-analyzer cargo zstd 0.13.3 stream/write/Decoder#::newrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'static, W>`]new().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().auto_flushrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Decoder<'a, W>`]auto_flush().()); |
| 449 | _assert_sendrust-analyzer cargo zstd 0.13.3 stream/write/_assert_send().(Encoderrust-analyzer cargo zstd 0.13.3 stream/write/Encoder#::newrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'static, W>`]new().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), 1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().auto_finishrust-analyzer cargo zstd 0.13.3 stream/write/impl#[`Encoder<'a, W>`]auto_finish().()); |
| 450 | } |