Skip to content

Commit adf2e9e

Browse files
committed
main fn and complete
1 parent f93827a commit adf2e9e

File tree

7 files changed

+58
-21
lines changed

7 files changed

+58
-21
lines changed

src/data_structures/bitfield/bitfield.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,27 @@ use bitflags::bitflags;
1212
use std::fmt;
1313
1414
bitflags! {
15+
#[derive(PartialEq, Debug, Copy, Clone)]
1516
struct MyFlags: u32 {
1617
const FLAG_A = 0b00000001;
1718
const FLAG_B = 0b00000010;
1819
const FLAG_C = 0b00000100;
19-
const FLAG_ABC = Self::FLAG_A.bits
20-
| Self::FLAG_B.bits
21-
| Self::FLAG_C.bits;
20+
const FLAG_ABC = Self::FLAG_A.bits()
21+
| Self::FLAG_B.bits()
22+
| Self::FLAG_C.bits();
2223
}
2324
}
2425
2526
impl MyFlags {
2627
pub fn clear(&mut self) -> &mut MyFlags {
27-
self.bits = 0;
28+
*self = MyFlags::empty();
2829
self
2930
}
3031
}
3132
3233
impl fmt::Display for MyFlags {
3334
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
34-
write!(f, "{:032b}", self.bits)
35+
write!(f, "{:032b}", self.bits())
3536
}
3637
}
3738
@@ -46,10 +47,6 @@ fn main() {
4647
let mut flags = MyFlags::FLAG_ABC;
4748
assert_eq!(format!("{}", flags), "00000000000000000000000000000111");
4849
assert_eq!(format!("{}", flags.clear()), "00000000000000000000000000000000");
49-
assert_eq!(format!("{:?}", MyFlags::FLAG_B), "FLAG_B");
50-
assert_eq!(format!("{:?}", MyFlags::FLAG_A | MyFlags::FLAG_B), "FLAG_A | FLAG_B");
50+
assert_eq!(format!("{:?}", MyFlags::FLAG_B), "MyFlags(FLAG_B)");
51+
assert_eq!(format!("{:?}", MyFlags::FLAG_A | MyFlags::FLAG_B), "MyFlags(FLAG_A | FLAG_B)");
5152
}
52-
```
53-
54-
[`bitflags!`]: https://docs.rs/bitflags/*/bitflags/macro.bitflags.html
55-
[`Display`]: https://doc.rust-lang.org/std/fmt/trait.Display.html

src/encoding/csv/transform.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Transform a CSV file containing a color name and a hex color into one with a
66
color name and an rgb color. Utilizes the [csv] crate to read and write the
77
csv file, and [serde] to deserialize and serialize the rows to and from bytes.
88

9-
See [`csv::Reader::deserialize`], [`serde::Deserialize`], and [`std::str::FromStr`]
9+
See [csv::Reader::deserialize], [serde::Deserialize], and [std::str::FromStr]
1010

1111
```rust,edition2018
1212
extern crate csv;
@@ -82,7 +82,7 @@ magenta,#ff00ff"
8282
Ok(())
8383
}
8484
85-
[`csv::Reader::deserialize`]: https://docs.rs/csv/\*/csv/struct.Reader.html#method.deserialize
86-
[`csv::invalid_option`]: https://docs.rs/csv/*/csv/fn.invalid_option.html
87-
[`serde::Deserialize`]: https://docs.rs/serde/\*/serde/trait.Deserialize.html
88-
[`std::str::FromStr`]: https://doc.rust-lang.org/std/str/trait.FromStr.html
85+
[csv::Reader::deserialize]: https://docs.rs/csv/*/csv/struct.Reader.html#method.deserialize
86+
[csv::invalid_option]: https://docs.rs/csv/*/csv/fn.invalid_option.html
87+
[serde::Deserialize]: https://docs.rs/serde/*/serde/trait.Deserialize.html
88+
[std::str::FromStr]: https://doc.rust-lang.org/std/str/trait.FromStr.html

src/errors/handle/main.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ As recommended in Rust by Example, [`Box`ing errors] is seen as an easy
1010
strategy for getting started.
1111

1212
```rust,edition2018
13-
Box<dyn Error>
14-
````
13+
use std::error::Error;
14+
15+
fn main() -> Result<(), Box<dyn Error>> {
16+
// Example of boxing errors
17+
let result: Result<(), Box<dyn Error>> = Ok(());
18+
result
19+
}
20+
```
1521

1622
To understand what kind of error handling may be required study [Designing
1723
error types in Rust] and consider [`thiserror`] for libraries or [`anyhow`] as
@@ -26,6 +32,11 @@ pub enum MultiError {
2632
#[error("🦀 got {0}")]
2733
ErrorClass(String),
2834
}
35+
36+
fn main() -> Result<(), MultiError> {
37+
// Example of using thiserror
38+
Err(MultiError::ErrorClass("example error".to_string()))
39+
}
2940
```
3041

3142
Application authors can compose enums using `anyhow` can import the `Result`

src/file/dir/loops.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ln -s /tmp/foo/ /tmp/foo/bar/baz/qux
1010
```
1111
The following would assert that a loop exists.
1212

13-
```rust,edition2018
13+
```rust,edition2018,no_run
1414
extern crate walkdir;
1515
extern crate same_file;
1616
use walkdir::WalkDir;

src/file/dir/recursive.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
```rust,edition2018
22
extern crate walkdir;
3-
use walkdir::WalkDir;
3+
use walkdir::WalkDir;
4+
5+
fn main() {
6+
// Example of using WalkDir to recursively traverse directories
7+
for entry in WalkDir::new(".").max_depth(2) {
8+
match entry {
9+
Ok(entry) => println!("{}", entry.path().display()),
10+
Err(e) => eprintln!("Error: {}", e),
11+
}
12+
}
13+
}
14+
```

src/file/read-write/same-file.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Use [`same_file::Handle`] to a file that can be tested for equality with
66
other handles. In this example, the handles of file to be read from and
77
to be written to are tested for equality.
88

9-
```rust,edition2018
9+
```rust,edition2018,no_run
1010
extern crate same_file;
1111
use same_file::{is_same_file, Handle};
1212
use std::fs::File;

src/file/read/read_lines.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,22 @@ extern crate tempfile;
33
use std::fs::File;
44
use std::io::{self, BufRead, BufReader, Write};
55
use tempfile::NamedTempFile;
6+
7+
fn main() -> io::Result<()> {
8+
// Create a temporary file with some content
9+
let mut temp_file = NamedTempFile::new()?;
10+
writeln!(temp_file, "Line 1")?;
11+
writeln!(temp_file, "Line 2")?;
12+
writeln!(temp_file, "Line 3")?;
13+
14+
// Read lines from the file
15+
let file = File::open(temp_file.path())?;
16+
let reader = BufReader::new(file);
17+
18+
for (index, line) in reader.lines().enumerate() {
19+
println!("Line {}: {}", index + 1, line?);
20+
}
21+
22+
Ok(())
23+
}
624
```

0 commit comments

Comments
 (0)