Skip to content

Commit d8828f5

Browse files
committed
update original
1 parent 99e9ef5 commit d8828f5

23 files changed

Lines changed: 378 additions & 25 deletions

rust-cookbook/CONTRIBUTING.md

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,32 +157,25 @@ crates: we decide which crates to represent in the cookbook, then come
157157
up with example use cases to write, then write the examples. And those
158158
are the three basic, recurring types of contributions needed.
159159

160-
The development process for the cookbook today is tied to the [libz
161-
blitz], a broader project to improve the Rust crate ecosystem, and the
162-
cookbook presently represents the crates under consideration there.
163-
The easiest way to find the most immediate work needed for the
164-
cookbook is to follow the "What's next" section at the top of that
165-
thread, which should at all times link to something to contribute to
166-
the cookbook.
167-
168-
Otherwise, look for GitHub issues with the [example] tag. The simplest
169-
way to contribute is to claim one of these examples, and submit a PR
170-
adding it. If you do claim one, please leave a comment saying so, so
171-
others don't accidentally duplicate your work.
160+
Look for GitHub issues with the [example] tag. The simplest way to
161+
contribute is to claim one of these examples, and submit a PR adding
162+
it. If you do claim one, please leave a comment saying so, so others
163+
don't accidentally duplicate your work.
172164

173165
If you have an idea for an example for a specific crate, please
174166
suggest it on the relevant [tracking issue].
175167

176-
Please do not submit examples for crates not yet represented in the
177-
cookbook, unless it is part of the libz blitz crate schedule.
178-
Contribution will be open to a broader set of crates in the future.
179-
For more about which crates are represented in the cookbook, see ["a
180-
note about crate representation"][which-crates] in the cookbook.
168+
A crate should generally only be added to the cookbook if it is the
169+
(or a) recommendation for its problem domain on [blessed.rs], or ranks
170+
at or near the top of its [crates.io] category by downloads. For more
171+
about which crates are represented in the cookbook, see ["a note about
172+
crate representation"][which-crates] in the cookbook.
181173

182174
[example]: https://github.com/rust-lang-nursery/rust-cookbook/issues?q=is%3Aissue+is%3Aopen+label%3Aexample
183175
[tracking issue]: https://github.com/rust-lang-nursery/rust-cookbook/issues?q=is%3Aissue+is%3Aopen+label%3A%22tracking+issue%22
184176
[which-crates]: https://rust-lang-nursery.github.io/rust-cookbook/about.html#a-note-about-crate-representation
185-
[libz blitz]: https://internals.rust-lang.org/t/rust-libz-blitz/5184
177+
[blessed.rs]: https://blessed.rs
178+
[crates.io]: https://crates.io
186179

187180
## Adding an example
188181

rust-cookbook/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["crates/algorithms/*", "crates/concurrency/*", "crates/configuration/*", "crates/development_tools/build_tools/*", "crates/development_tools/debugging/tracing", "crates/file/*", "crates/multimedia/*", "crates/parsing/*", "crates/safety_critical/*", "crates/wasm", "crates/web", "xtask"]
2+
members = ["crates/algorithms/*", "crates/compression/*", "crates/concurrency/*", "crates/configuration/*", "crates/development_tools/build_tools/*", "crates/development_tools/debugging/tracing", "crates/file/*", "crates/multimedia/*", "crates/parsing/*", "crates/safety_critical/*", "crates/wasm", "crates/web", "xtask"]
33
exclude = ["crates/database/sea_orm", "crates/database/sqlx", "crates/multimedia/playback", "crates/web_leptos", "crates/web_leptos_hydrate", "crates/wasm_component_guest", "crates/wasm_component_host"]
44

55
[workspace.package]

rust-cookbook/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const REMOVED_TESTS: &[&str] = &[
1515

1616
const REMOVED_PREFIXES: &[&str] = &[
1717
"./src/algorithms/randomness/",
18+
"./src/compression/bzip2/",
1819
"./src/configuration/",
1920
"./src/development_tools/build_tools/",
2021
"./src/development_tools/debugging/tracing/",

rust-cookbook/ci/dictionary.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ bufwriter
6060
byteorder
6161
ByteRecord
6262
bytestring
63+
bzip
6364
cAFeEDEcafBAd
6465
CannotBeABase
6566
ccccff
@@ -149,6 +150,7 @@ GlobError
149150
graphemes
150151
Graphemes
151152
Guybrush
153+
gzip
152154
GzDecoder
153155
GzEncoder
154156
Hackerman
@@ -212,6 +214,7 @@ LazyLock
212214
leptos
213215
Leptos
214216
LevelFilter
217+
libc
215218
libhello
216219
Libz
217220
linux
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "bzip2-example"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
publish.workspace = true
8+
9+
[dependencies]
10+
bzip2 = "0.6"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use bzip2::Compression;
2+
use bzip2::write::BzEncoder;
3+
use std::fs::File;
4+
use std::io;
5+
6+
fn main() -> io::Result<()> {
7+
let mut input = File::open("input.txt")?;
8+
let output = File::create("input.txt.bz2")?;
9+
let mut encoder = BzEncoder::new(output, Compression::best());
10+
io::copy(&mut input, &mut encoder)?;
11+
encoder.finish()?;
12+
Ok(())
13+
}
14+
15+
#[cfg(test)]
16+
mod tests {
17+
use super::*;
18+
use bzip2::read::BzDecoder;
19+
use std::io::{Read, Write};
20+
21+
#[test]
22+
fn round_trips_through_bzip2() -> io::Result<()> {
23+
let data = b"hello, bzip2!".repeat(100);
24+
25+
let mut encoder = BzEncoder::new(Vec::new(), Compression::best());
26+
encoder.write_all(&data)?;
27+
let compressed = encoder.finish()?;
28+
29+
let mut decoder = BzDecoder::new(compressed.as_slice());
30+
let mut decompressed = Vec::new();
31+
decoder.read_to_end(&mut decompressed)?;
32+
33+
assert_eq!(decompressed, data);
34+
Ok(())
35+
}
36+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use bzip2::read::BzDecoder;
2+
use std::fs::File;
3+
use std::io;
4+
5+
fn main() -> io::Result<()> {
6+
let input = File::open("input.txt.bz2")?;
7+
let mut decoder = BzDecoder::new(input);
8+
let mut output = File::create("input.txt")?;
9+
io::copy(&mut decoder, &mut output)?;
10+
Ok(())
11+
}
12+
13+
#[cfg(test)]
14+
mod tests {
15+
use super::*;
16+
use bzip2::Compression;
17+
use bzip2::write::BzEncoder;
18+
use std::io::{Read, Write};
19+
20+
#[test]
21+
fn decodes_bzip2_compressed_bytes() -> io::Result<()> {
22+
let data = b"hello, bzip2!".repeat(100);
23+
24+
let mut encoder = BzEncoder::new(Vec::new(), Compression::best());
25+
encoder.write_all(&data)?;
26+
let compressed = encoder.finish()?;
27+
28+
let mut decoder = BzDecoder::new(compressed.as_slice());
29+
let mut decompressed = Vec::new();
30+
decoder.read_to_end(&mut decompressed)?;
31+
32+
assert_eq!(decompressed, data);
33+
Ok(())
34+
}
35+
}

rust-cookbook/src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
- [Environment Variables](cli/env.md)
2323
- [Compression](compression.md)
2424
- [Working with Tarballs](compression/tar.md)
25+
- [Working with Gzip](compression/gzip.md)
26+
- [Working with Bzip2](compression/bzip2.md)
2527
- [Concurrency](concurrency.md)
2628
- [Explicit Threads](concurrency/threads.md)
2729
- [Synchronization Primitives](concurrency/sync.md)

rust-cookbook/src/about.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,27 @@ At present the cookbook is focused on the standard library, and on
114114
common programming tasks, and that the rest of the ecosystem builds
115115
off of.
116116

117-
The cookbook is closely tied to the [Rust Libz Blitz], a project to
118-
identify, and improve the quality of such crates, and so it largely
119-
defers crate selection to that project. Any crates that have already
120-
been evaluated as part of that process are in scope for the cookbook,
121-
as are crates that are pending evaluation.
117+
A crate is in scope for the cookbook if it meets one of these bars:
118+
119+
- It is the (or a) recommendation for its problem domain on
120+
[blessed.rs], a curated guide to which crate to reach for in a given
121+
situation.
122+
- It ranks at or near the top of its [crates.io] category, sorted by
123+
downloads. Category rank matters more than raw download count, since
124+
aggregate downloads favor old, low-level crates (like `libc` or
125+
`syn`) that aren't cookbook material on their own.
126+
127+
Either way, the crate should also be actively maintained (a release or
128+
commit within the last year), have [docs.rs] documentation, and use a
129+
standard OSI license.
122130

123131
{{#include links.md}}
124132

125133
[index]: intro.html
126134
[error-docs]: https://doc.rust-lang.org/book/ch09-00-error-handling.html
127135
[error-blog]: https://brson.github.io/2016/11/30/starting-with-error-chain
128136
[error-chain]: https://docs.rs/error-chain/
129-
[Rust Libz Blitz]: https://internals.rust-lang.org/t/rust-libz-blitz/5184
137+
[blessed.rs]: https://blessed.rs
130138
[crates.io]: https://crates.io
131139
[docs.rs]: https://docs.rs
132140
[Cargo.toml]: http://doc.crates.io/manifest.html

rust-cookbook/src/compression.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@
55
| [Decompress a tarball][ex-tar-decompress] | [![flate2-badge]][flate2] [![tar-badge]][tar] | [![cat-compression-badge]][cat-compression] |
66
| [Compress a directory into a tarball][ex-tar-compress] | [![flate2-badge]][flate2] [![tar-badge]][tar] | [![cat-compression-badge]][cat-compression] |
77
| [Decompress a tarball while removing a prefix from the paths][ex-tar-strip-prefix] | [![flate2-badge]][flate2] [![tar-badge]][tar] | [![cat-compression-badge]][cat-compression] |
8+
| [Decompress a gzip file][ex-gzip-decompress] | [![flate2-badge]][flate2] | [![cat-compression-badge]][cat-compression] |
9+
| [Compress a file with gzip][ex-gzip-compress] | [![flate2-badge]][flate2] | [![cat-compression-badge]][cat-compression] |
10+
| [Decompress a bzip2 file][ex-bzip2-decompress] | [![bzip2-badge]][bzip2] | [![cat-compression-badge]][cat-compression] |
11+
| [Compress a file with bzip2][ex-bzip2-compress] | [![bzip2-badge]][bzip2] | [![cat-compression-badge]][cat-compression] |
812

913
[ex-tar-decompress]: compression/tar.html#decompress-a-tarball
1014
[ex-tar-compress]: compression/tar.html#compress-a-directory-into-tarball
1115
[ex-tar-strip-prefix]: compression/tar.html#decompress-a-tarball-while-removing-a-prefix-from-the-paths
16+
[ex-gzip-decompress]: compression/gzip.html#decompress-a-gzip-file
17+
[ex-gzip-compress]: compression/gzip.html#compress-a-file-with-gzip
18+
[ex-bzip2-decompress]: compression/bzip2.html#decompress-a-bzip2-file
19+
[ex-bzip2-compress]: compression/bzip2.html#compress-a-file-with-bzip2
1220

1321
{{#include links.md}}

0 commit comments

Comments
 (0)