Formatter

This commit is contained in:
LukeMathWalker
2024-05-24 18:16:20 +02:00
parent 1aae615bb4
commit 4401743807
36 changed files with 0 additions and 36 deletions

View File

@@ -13,4 +13,3 @@ We'll need to introduce a few more concepts along the way:
- The `Error` trait, to mark error types
- The `TryFrom` and `TryInto` traits, for fallible conversions
- Rust's package system, explaining what's a library, what's a binary, how to use third-party crates

View File

@@ -41,4 +41,3 @@ enum Status {
```
`enum`, just like `struct`, defines **a new Rust type**.

View File

@@ -68,4 +68,3 @@ match status {
```
The `_` pattern matches anything that wasn't matched by the previous patterns.

View File

@@ -86,4 +86,3 @@ match status {
}
}
```

View File

@@ -64,4 +64,3 @@ as the code that precedes it.
Both `if let` and `let/else` are idiomatic Rust constructs.\
Use them as you see fit to improve the readability of your code,
but don't overdo it: `match` is always there when you need it.

View File

@@ -72,4 +72,3 @@ assert_eq!(second.2, 8);
```
Tuples are a convenient way of grouping values together when you can't be bothered to define a dedicated struct type.

View File

@@ -81,4 +81,3 @@ That's the big advantage of `Result`: it makes fallibility explicit.
Keep in mind, though, that panics exist. They aren't tracked by the type system, just like exceptions in other languages.
But they're meant for **unrecoverable errors** and should be used sparingly.

View File

@@ -38,4 +38,3 @@ When you call a function that returns a `Result`, you have two key options:
Err(err) => eprintln!("Error: {}", err),
}
```

View File

@@ -36,4 +36,3 @@ match s.parse_u32() {
}
}
```

View File

@@ -50,4 +50,3 @@ The difference is in their _purpose_: `Display` returns a representation that's
while `Debug` provides a low-level representation that's more suitable to developers and service operators.\
That's why `Debug` can be automatically implemented using the `#[derive(Debug)]` attribute, while `Display`
**requires** a manual implementation.

View File

@@ -61,4 +61,3 @@ binary crate inside. If you want to create a library crate instead, you can use
```bash
cargo new my-library --lib
```

View File

@@ -52,4 +52,3 @@ static_assertions = "1.1.0"
```
We've been using a few of these throughout the book to shorten our tests.

View File

@@ -39,4 +39,3 @@ In the case of `thiserror`, we have:
- `#[derive(thiserror::Error)]`: this is the syntax to derive the `Error` trait for a custom error type, helped by `thiserror`.
- `#[error("{0}")]`: this is the syntax to define a `Display` implementation for each variant of the custom error type.
`{0}` is replaced by the zero-th field of the variant (`String`, in this case) when the error is displayed.

View File

@@ -38,4 +38,3 @@ being attempted.
Just like `From` and `Into`, `TryFrom` and `TryInto` are dual traits.\
If you implement `TryFrom` for a type, you get `TryInto` for free.

View File

@@ -148,4 +148,3 @@ fn read_file() -> Result<String, std::io::Error> {
You can use the `?` operator to shorten your error handling code significantly.\
In particular, the `?` operator will automatically convert the error type of the fallible operation into the error type
of the function, if a conversion is possible (i.e. if there is a suitable `From` implementation)