Skip to content

Commit cb949b0

Browse files
KappaDistributiveAndyGauge
authored andcommitted
removed error-chain from examples having only one error variant (rust-lang-nursery#525)
* removed error-chain from 'Calculate SHA1 sum of iso files concurrently' * removed error chain from 'Salt and hash a password with PBKDF2' * removed error-chain from 'Parse string into DateTime struct' * removed error-chain from 'Log messages with a custom logger' * fixed compiler errors * removed unnecessary feature flag * removed error-chain from 'Log to the Unix syslog' * removed error-chain from 'Parse and increment a version string.' * removed error-chain from 'Parse a complex version string.' * removed error-chain from 'Check if given version is pre-release.' * removed error-chain from 'Percent-encode a string' * removed error-chain from 'Encode and decode hex' * removed error-chain from 'Read CSV records' * removed error-chain from 'Read CSV records with different delimiter' * removed error-chain from 'Handle invalid CSV data with Serde' * removed error-chain from 'Serialize and deserialize unstructured JSON' * removed error-chain from 'Deserialize a TOML configuration file' * removed error-chain from 'Read and write integers in little-endian byte order' * removed error-chain from 'Read lines of strings from a file' * removed error-chain from 'Avoid writing and reading from a same file' * removed error-chain from 'Access a file randomly using a memory map' * removed error-chain from 'Listen on unused port TCP/IP' * removed error-chain from 'Redirect both stdout and stderr of child process to the same file' * removed error-chain from 'Continuously process child process' outputs' * removed error-chain from 'Parse a URL from a string to a `Url` type' * removed error-chain from 'Create new URLs from a base URL' * removed error-chain from 'Extract the URL origin (scheme / host / port)' * removed error-chain from 'Remove fragment identifiers and query pairs from a URL' * removed error-chain from 'Query the GitHub API' * removed error-chain from 'Check if an API resource exists' * removed error-chain from 'Consume a paginated RESTful API' * addressed Travis CI failure * addressed Travis CI failure * addressed Travis CI issue
1 parent 99e3d6b commit cb949b0

30 files changed

+130
-421
lines changed

src/concurrency/thread/threadpool-walk.md

+4-14
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,14 @@ the current directory and calls [`execute`] to perform the operations of reading
99
and computing SHA1 hash.
1010

1111
```rust,no_run
12-
# #[macro_use]
13-
# extern crate error_chain;
1412
extern crate walkdir;
1513
extern crate ring;
1614
extern crate num_cpus;
1715
extern crate threadpool;
1816
19-
# error_chain! {
20-
# foreign_links {
21-
# Io(std::io::Error);
22-
# }
23-
# }
24-
#
2517
use walkdir::WalkDir;
2618
use std::fs::File;
27-
use std::io::{BufReader, Read};
19+
use std::io::{BufReader, Read, Error};
2820
use std::path::Path;
2921
use threadpool::ThreadPool;
3022
use std::sync::mpsc::channel;
@@ -37,8 +29,8 @@ use ring::digest::{Context, Digest, SHA1};
3729
# _ => false,
3830
# }
3931
# }
40-
#
41-
fn compute_digest<P: AsRef<Path>>(filepath: P) -> Result<(Digest, P)> {
32+
33+
fn compute_digest<P: AsRef<Path>>(filepath: P) -> Result<(Digest, P), Error> {
4234
let mut buf_reader = BufReader::new(File::open(&filepath)?);
4335
let mut context = Context::new(&SHA1);
4436
let mut buffer = [0; 1024];
@@ -54,7 +46,7 @@ fn compute_digest<P: AsRef<Path>>(filepath: P) -> Result<(Digest, P)> {
5446
Ok((context.finish(), filepath))
5547
}
5648
57-
fn run() -> Result<()> {
49+
fn main() -> Result<(), Error> {
5850
let pool = ThreadPool::new(num_cpus::get());
5951
6052
let (tx, rx) = channel();
@@ -79,8 +71,6 @@ fn run() -> Result<()> {
7971
}
8072
Ok(())
8173
}
82-
#
83-
# quick_main!(run);
8474
```
8575

8676
[`execute`]: https://docs.rs/threadpool/*/threadpool/struct.ThreadPool.html#method.execute

src/cryptography/encryption/pbkdf2.md

+38-47
Original file line numberDiff line numberDiff line change
@@ -10,64 +10,55 @@ function [`pbkdf2::derive`]. Verifies the hash is correct with
1010
securely generated random numbers.
1111

1212
```rust
13-
# #[macro_use]
14-
# extern crate error_chain;
15-
extern crate data_encoding;
1613
extern crate ring;
17-
#
18-
# error_chain! {
19-
# foreign_links {
20-
# Ring(ring::error::Unspecified);
21-
# }
22-
# }
14+
extern crate data_encoding;
2315

2416
use data_encoding::HEXUPPER;
25-
use ring::{digest, pbkdf2, rand};
17+
use ring::error::Unspecified;
2618
use ring::rand::SecureRandom;
19+
use ring::{digest, pbkdf2, rand};
2720

28-
fn run() -> Result<()> {
29-
const CREDENTIAL_LEN: usize = digest::SHA512_OUTPUT_LEN;
30-
const N_ITER: u32 = 100_000;
31-
let rng = rand::SystemRandom::new();
21+
fn main() -> Result<(), Unspecified> {
22+
const CREDENTIAL_LEN: usize = digest::SHA512_OUTPUT_LEN;
23+
const N_ITER: u32 = 100_000;
24+
let rng = rand::SystemRandom::new();
3225

33-
let mut salt = [0u8; CREDENTIAL_LEN];
34-
rng.fill(&mut salt)?;
26+
let mut salt = [0u8; CREDENTIAL_LEN];
27+
rng.fill(&mut salt)?;
3528

36-
let password = "Guess Me If You Can!";
37-
let mut pbkdf2_hash = [0u8; CREDENTIAL_LEN];
38-
pbkdf2::derive(
39-
&digest::SHA512,
40-
N_ITER,
41-
&salt,
42-
password.as_bytes(),
43-
&mut pbkdf2_hash,
44-
);
45-
println!("Salt: {}", HEXUPPER.encode(&salt));
46-
println!("PBKDF2 hash: {}", HEXUPPER.encode(&pbkdf2_hash));
29+
let password = "Guess Me If You Can!";
30+
let mut pbkdf2_hash = [0u8; CREDENTIAL_LEN];
31+
pbkdf2::derive(
32+
&digest::SHA512,
33+
N_ITER,
34+
&salt,
35+
password.as_bytes(),
36+
&mut pbkdf2_hash,
37+
);
38+
println!("Salt: {}", HEXUPPER.encode(&salt));
39+
println!("PBKDF2 hash: {}", HEXUPPER.encode(&pbkdf2_hash));
4740

48-
let should_succeed = pbkdf2::verify(
49-
&digest::SHA512,
50-
N_ITER,
51-
&salt,
52-
password.as_bytes(),
53-
&pbkdf2_hash,
54-
);
55-
let wrong_password = "Definitely not the correct password";
56-
let should_fail = pbkdf2::verify(
57-
&digest::SHA512,
58-
N_ITER,
59-
&salt,
60-
wrong_password.as_bytes(),
61-
&pbkdf2_hash,
62-
);
41+
let should_succeed = pbkdf2::verify(
42+
&digest::SHA512,
43+
N_ITER,
44+
&salt,
45+
password.as_bytes(),
46+
&pbkdf2_hash,
47+
);
48+
let wrong_password = "Definitely not the correct password";
49+
let should_fail = pbkdf2::verify(
50+
&digest::SHA512,
51+
N_ITER,
52+
&salt,
53+
wrong_password.as_bytes(),
54+
&pbkdf2_hash,
55+
);
6356

64-
assert!(should_succeed.is_ok());
65-
assert!(!should_fail.is_ok());
57+
assert!(should_succeed.is_ok());
58+
assert!(!should_fail.is_ok());
6659

67-
Ok(())
60+
Ok(())
6861
}
69-
#
70-
# quick_main!(run);
7162
```
7263

7364
[`pbkdf2::derive`]: https://briansmith.org/rustdoc/ring/pbkdf2/fn.derive.html

src/cryptography/hashing/hmac.md

+2-11
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,13 @@
55
Uses [`ring::hmac`] to creates a [`hmac::Signature`] of a string then verifies the signature is correct.
66

77
```rust
8-
# #[macro_use]
9-
# extern crate error_chain;
108
extern crate ring;
11-
#
12-
# error_chain! {
13-
# foreign_links {
14-
# Ring(ring::error::Unspecified);
15-
# }
16-
# }
179

1810
use ring::{digest, hmac, rand};
1911
use ring::rand::SecureRandom;
12+
use ring::error::Unspecified;
2013

21-
fn run() -> Result<()> {
14+
fn main() -> Result<(), Unspecified> {
2215
let mut key_value = [0u8; 48];
2316
let rng = rand::SystemRandom::new();
2417
rng.fill(&mut key_value)?;
@@ -30,8 +23,6 @@ fn run() -> Result<()> {
3023

3124
Ok(())
3225
}
33-
#
34-
# quick_main!(run);
3526
```
3627

3728
[`hmac::Signature`]: https://briansmith.org/rustdoc/ring/hmac/struct.Signature.html

src/datetime/parse/string.md

+3-12
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,11 @@ identifies a date and a time. For parsing dates and times without timezones use
1515

1616
```rust
1717
extern crate chrono;
18-
# #[macro_use]
19-
# extern crate error_chain;
20-
#
2118
use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime};
22-
#
23-
# error_chain! {
24-
# foreign_links {
25-
# DateParse(chrono::format::ParseError);
26-
# }
27-
# }
19+
use chrono::format::ParseError;
2820

29-
fn run() -> Result<()> {
21+
22+
fn main() -> Result<(), ParseError> {
3023
let rfc2822 = DateTime::parse_from_rfc2822("Tue, 1 Jul 2003 10:52:37 +0200")?;
3124
println!("{}", rfc2822);
3225

@@ -47,8 +40,6 @@ fn run() -> Result<()> {
4740

4841
Ok(())
4942
}
50-
#
51-
# quick_main!(run);
5243
```
5344

5445
[`chrono::format::strftime`]: https://docs.rs/chrono/*/chrono/format/strftime/index.html

src/development_tools/debugging/log/log-custom-logger.md

+3-13
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ In order to use the logging macros, `ConsoleLogger` implements
77
the [`log::Log`] trait and [`log::set_logger`] installs it.
88

99
```rust
10-
# #[macro_use]
11-
# extern crate error_chain;
1210
#[macro_use]
1311
extern crate log;
1412

15-
use log::{Record, Level, Metadata, LevelFilter};
13+
use log::{Record, Level, Metadata, LevelFilter, SetLoggerError};
1614

1715
static CONSOLE_LOGGER: ConsoleLogger = ConsoleLogger;
1816

@@ -31,14 +29,8 @@ impl log::Log for ConsoleLogger {
3129

3230
fn flush(&self) {}
3331
}
34-
#
35-
# error_chain! {
36-
# foreign_links {
37-
# SetLogger(log::SetLoggerError);
38-
# }
39-
# }
40-
41-
fn run() -> Result<()> {
32+
33+
fn main() -> Result<(), SetLoggerError> {
4234
log::set_logger(&CONSOLE_LOGGER)?;
4335
log::set_max_level(LevelFilter::Info);
4436

@@ -47,8 +39,6 @@ fn run() -> Result<()> {
4739
error!("oops");
4840
Ok(())
4941
}
50-
#
51-
# quick_main!(run);
5242
```
5343

5444
[`log::Log`]: https://docs.rs/log/*/log/trait.Log.html

src/development_tools/debugging/log/log-syslog.md

+5-19
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,28 @@ the log entry's classification, [`log::LevelFilter`] denotes allowed log verbosi
88
and `Option<&str>` holds optional application name.
99

1010
```rust
11-
# #![allow(unused_imports)]
12-
# #[macro_use]
13-
# extern crate error_chain;
1411
#[macro_use]
1512
extern crate log;
1613
# #[cfg(target_os = "linux")]
1714
extern crate syslog;
1815

1916
# #[cfg(target_os = "linux")]
20-
use syslog::Facility;
21-
#
22-
# #[cfg(target_os = "linux")]
23-
# error_chain! {
24-
# foreign_links {
25-
# SetLogger(syslog::Error);
26-
# }
27-
# }
17+
use syslog::{Facility, Error};
2818

2919
# #[cfg(target_os = "linux")]
30-
fn run() -> Result<()> {
20+
fn main() -> Result<(), Error> {
3121
syslog::init(Facility::LOG_USER,
3222
log::LevelFilter::Debug,
3323
Some("My app name"))?;
3424
debug!("this is a debug {}", "message");
3525
error!("this is an error!");
3626
Ok(())
3727
}
38-
#
39-
# #[cfg(not(target_os = "linux"))]
40-
# error_chain! {}
28+
4129
# #[cfg(not(target_os = "linux"))]
42-
# fn run() -> Result<()> {
43-
# Ok(())
30+
# fn main() {
31+
# println!("So far, only Linux systems are supported.");
4432
# }
45-
#
46-
# quick_main!(run);
4733
```
4834

4935
[`log::LevelFilter`]: https://docs.rs/log/*/log/enum.LevelFilter.html

src/development_tools/versioning/semver-complex.md

+2-12
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,11 @@ Note that, in accordance with the Specification, build metadata is parsed but no
99
comparing versions. In other words, two versions may be equal even if their build strings differ.
1010

1111
```rust
12-
# #[macro_use]
13-
# extern crate error_chain;
1412
extern crate semver;
1513

16-
use semver::{Identifier, Version};
17-
#
18-
# error_chain! {
19-
# foreign_links {
20-
# SemVer(semver::SemVerError);
21-
# }
22-
# }
14+
use semver::{Identifier, Version, SemVerError};
2315

24-
fn run() -> Result<()> {
16+
fn main() -> Result<(), SemVerError> {
2517
let version_str = "1.0.49-125+g72ee7853";
2618
let parsed_version = Version::parse(version_str)?;
2719

@@ -45,8 +37,6 @@ fn run() -> Result<()> {
4537

4638
Ok(())
4739
}
48-
#
49-
# quick_main!(run);
5040
```
5141

5242
[`semver::Version`]: https://docs.rs/semver/*/semver/struct.Version.html

src/development_tools/versioning/semver-increment.md

+2-12
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,11 @@ incrementing the major version number resets both the minor and patch version
1111
numbers to 0.
1212

1313
```rust
14-
# #[macro_use]
15-
# extern crate error_chain;
1614
extern crate semver;
1715

18-
use semver::Version;
19-
#
20-
# error_chain! {
21-
# foreign_links {
22-
# SemVer(semver::SemVerError);
23-
# }
24-
# }
16+
use semver::{Version, SemVerError};
2517

26-
fn run() -> Result<()> {
18+
fn main() -> Result<(), SemVerError> {
2719
let mut parsed_version = Version::parse("0.2.6")?;
2820

2921
assert_eq!(
@@ -51,8 +43,6 @@ fn run() -> Result<()> {
5143

5244
Ok(())
5345
}
54-
#
55-
# quick_main!(run);
5646
```
5747

5848
[`semver::Version`]: https://docs.rs/semver/*/semver/struct.Version.html

src/development_tools/versioning/semver-prerelease.md

+2-12
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,11 @@
55
Given two versions, [`is_prerelease`] asserts that one is pre-release and the other is not.
66

77
```rust
8-
# #[macro_use]
9-
# extern crate error_chain;
108
extern crate semver;
119

12-
use semver::Version;
13-
#
14-
# error_chain! {
15-
# foreign_links {
16-
# SemVer(semver::SemVerError);
17-
# }
18-
# }
10+
use semver::{Version, SemVerError};
1911

20-
fn run() -> Result<()> {
12+
fn main() -> Result<(), SemVerError> {
2113
let version_1 = Version::parse("1.0.0-alpha")?;
2214
let version_2 = Version::parse("1.0.0")?;
2315

@@ -26,8 +18,6 @@ fn run() -> Result<()> {
2618

2719
Ok(())
2820
}
29-
#
30-
# quick_main!(run);
3121
```
3222

3323
[`is_prerelease`]: https://docs.rs/semver/*/semver/struct.Version.html#method.is_prerelease

0 commit comments

Comments
 (0)