Debian Codegraph @

src/lz4f/stream/comp/write.rs

raw symbols SCIP
1 use superrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/::{Compressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#, Dictionaryrust-analyzer cargo lzzzz 2.0.0 lz4f/dictionary/Dictionary#, Preferencesrust-analyzer cargo lzzzz 2.0.0 lz4f/preferences/Preferences#};
2 use craterust-analyzer cargo lzzzz 2.0.0 crate/::lz4frust-analyzer cargo lzzzz 2.0.0 lz4f/::Resultrust-analyzer cargo lzzzz 2.0.0 lz4f/error/Result#;
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, iorust-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#};
4
5 /// The [`Write`]-based streaming compressor.
6 ///
7 /// # Example
8 ///
9 /// ```
10 /// # use std::env;
11 /// # use std::path::Path;
12 /// # use lzzzz::{Error, Result};
13 /// # use assert_fs::prelude::*;
14 /// # let tmp_dir = assert_fs::TempDir::new().unwrap().into_persistent();
15 /// # env::set_current_dir(tmp_dir.path()).unwrap();
16 /// use lzzzz::lz4f::WriteCompressor;
17 /// use std::{fs::File, io::prelude::*};
18 ///
19 /// let mut f = File::create("foo.lz4")?;
20 /// let mut w = WriteCompressor::new(&mut f, Default::default())?;
21 ///
22 /// w.write_all(b"Hello world!")?;
23 /// # Ok::<(), std::io::Error>(())
24 /// ```
25 ///
26 /// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
27 pub struct WriteCompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> {
28 innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#inner.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<W>,
29 comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#comp.: Compressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#,
30 }
31
32 impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> WriteCompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#<W> {
33 /// Creates a new `WriteCompressor<W>`.
34 pub fn newrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/impl#[`WriteCompressor<W>`]new().(writer: W, prefs: Preferencesrust-analyzer cargo lzzzz 2.0.0 lz4f/preferences/Preferences#) -> Resultrust-analyzer cargo lzzzz 2.0.0 lz4f/error/Result#<Selfrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/impl#[`WriteCompressor<W>`]> {
35 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/impl#[`WriteCompressor<W>`] {
36 innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#inner.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(writer),
37 comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#comp.: Compressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#::newrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]new().(prefs, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
38 })
39 }
40
41 /// Creates a new `WriteCompressor<W>` with a dictionary.
42 pub fn with_dictrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/impl#[`WriteCompressor<W>`]with_dict().(writer: W, prefs: Preferencesrust-analyzer cargo lzzzz 2.0.0 lz4f/preferences/Preferences#, dict: Dictionaryrust-analyzer cargo lzzzz 2.0.0 lz4f/dictionary/Dictionary#) -> Resultrust-analyzer cargo lzzzz 2.0.0 lz4f/error/Result#<Selfrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/impl#[`WriteCompressor<W>`]> {
43 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/impl#[`WriteCompressor<W>`] {
44 innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#inner.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(writer),
45 comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#comp.: Compressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/Compressor#::newrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]new().(prefs, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(dict))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
46 })
47 }
48
49 /// Returns a mutable reference to the writer.
50 pub fn get_mutrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/impl#[`WriteCompressor<W>`]get_mut().(&mut self) -> &mut W {
51 self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#inner..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().()
52 }
53
54 /// Returns a shared reference to the writer.
55 pub fn get_refrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/impl#[`WriteCompressor<W>`]get_ref().(&self) -> &W {
56 self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#inner..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().()
57 }
58
59 /// Returns the ownership of the writer, finishing the stream in the process.
60 pub fn into_innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/impl#[`WriteCompressor<W>`]into_inner().(mut self) -> W {
61 let _ = self.endrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/impl#[`WriteCompressor<W>`]end().();
62 self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#inner..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().()
63 }
64
65 fn endrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/impl#[`WriteCompressor<W>`]end().(&mut self) -> 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/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
66 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(device) = &mut self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#inner. {
67 self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#comp..endrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]end().(false)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
68 device.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#comp..bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]buf().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
69 self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#comp..clear_bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]clear_buf().();
70 device.flushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#flush().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
71 }
72
73 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
74 }
75 }
76
77 impl<W> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for WriteCompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#<W>
78 where
79 W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# + fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#,
80 {
81 fn fmtrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/impl#[`WriteCompressor<W>`][Debug]fmt().(&self, fmt: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
82 fmt.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("WriteCompressor")
83 .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("writer", &self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#inner.)
84 .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("prefs", &self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#comp..prefsrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]prefs().())
85 .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().()
86 }
87 }
88
89 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 WriteCompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#<W> {
90 fn writerust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/impl#[`WriteCompressor<W>`][Write]write().(&mut self, buf: &[u8]) -> 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/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> {
91 self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#comp..updaterust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]update().(buf, false)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
92 self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#inner..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().().write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#comp..bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]buf().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
93 self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#comp..clear_bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]clear_buf().();
94 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().())
95 }
96
97 fn flushrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/impl#[`WriteCompressor<W>`][Write]flush().(&mut self) -> 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/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
98 self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#comp..flushrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]flush().(false)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
99 self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#inner..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().().write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#comp..bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]buf().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
100 self.comprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#comp..clear_bufrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/impl#[Compressor]clear_buf().();
101 self.innerrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#inner..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 std https://github.com/rust-lang/rust/library/std io/Write#flush().()
102 }
103 }
104
105 impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for WriteCompressorrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/WriteCompressor#<W> {
106 fn droprust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/impl#[`WriteCompressor<W>`][Drop]drop().(&mut self) {
107 let _ = self.endrust-analyzer cargo lzzzz 2.0.0 lz4f/stream/comp/write/impl#[`WriteCompressor<W>`]end().();
108 }
109 }