From: LukeMathWalker <20745048+LukeMathWalker@users.noreply.github.com> Date: Fri, 24 May 2024 16:16:20 +0000 (+0200) Subject: Formatter X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=44017438070a5092d44222bce2202952d0e262b6;p=rust_exercises.git Formatter --- diff --git a/book/src/01_intro/01_syntax.md b/book/src/01_intro/01_syntax.md index af5eed0..746a22d 100644 --- a/book/src/01_intro/01_syntax.md +++ b/book/src/01_intro/01_syntax.md @@ -113,4 +113,3 @@ You can think of a type as a **tag** that the compiler attaches to every value i tag, the compiler can enforce different rules—e.g. you can't add a string to a number, but you can add two numbers together. If leveraged correctly, types can prevent whole classes of runtime bugs. - diff --git a/book/src/02_basic_calculator/00_intro.md b/book/src/02_basic_calculator/00_intro.md index 9a0d624..ebd5ff0 100644 --- a/book/src/02_basic_calculator/00_intro.md +++ b/book/src/02_basic_calculator/00_intro.md @@ -14,4 +14,3 @@ It might not sound like much, but it'll give us a chance to cover a lot of Rust' Nailing the basics with a few exercises will get the language flowing under your fingers. When we move on to more complex topics, such as traits and ownership, you'll be able to focus on the new concepts without getting bogged down by the syntax or other trivial details. - diff --git a/book/src/02_basic_calculator/03_if_else.md b/book/src/02_basic_calculator/03_if_else.md index 2ba20b0..3a6acfc 100644 --- a/book/src/02_basic_calculator/03_if_else.md +++ b/book/src/02_basic_calculator/03_if_else.md @@ -99,4 +99,3 @@ let message = if number < 5 { In the example above, each branch of the `if` evaluates to a string literal, which is then assigned to the `message` variable.\ The only requirement is that both `if` branches return the same type. - diff --git a/book/src/02_basic_calculator/05_factorial.md b/book/src/02_basic_calculator/05_factorial.md index e0d0c76..d31672a 100644 --- a/book/src/02_basic_calculator/05_factorial.md +++ b/book/src/02_basic_calculator/05_factorial.md @@ -9,4 +9,3 @@ So far you've learned: - How to execute conditional logic via comparisons and `if`/`else` expressions It looks like you're ready to tackle factorials! - diff --git a/book/src/03_ticket_v1/00_intro.md b/book/src/03_ticket_v1/00_intro.md index 903389a..8850e03 100644 --- a/book/src/03_ticket_v1/00_intro.md +++ b/book/src/03_ticket_v1/00_intro.md @@ -16,4 +16,3 @@ To move forward you'll have to pick up several new Rust concepts, such as: - Memory management: stack, heap, pointers, data layout, destructors - Modules and visibility - Strings - diff --git a/book/src/03_ticket_v1/01_struct.md b/book/src/03_ticket_v1/01_struct.md index a14d17e..9ff9069 100644 --- a/book/src/03_ticket_v1/01_struct.md +++ b/book/src/03_ticket_v1/01_struct.md @@ -136,4 +136,3 @@ let is_open = Ticket::is_open(ticket); The function call syntax makes it quite clear that `ticket` is being used as `self`, the first parameter of the method, but it's definitely more verbose. Prefer the method call syntax when possible. - diff --git a/book/src/03_ticket_v1/03_modules.md b/book/src/03_ticket_v1/03_modules.md index 7de10f0..ee801fd 100644 --- a/book/src/03_ticket_v1/03_modules.md +++ b/book/src/03_ticket_v1/03_modules.md @@ -112,4 +112,3 @@ where each name comes from and potentially introducing name conflicts.\ Nonetheless, it can be useful in some cases, like when writing unit tests. You might have noticed that most of our test modules start with a `use super::*;` statement to bring all the items from the parent module (the one being tested) into scope. - diff --git a/book/src/03_ticket_v1/04_visibility.md b/book/src/03_ticket_v1/04_visibility.md index 6338857..29b53c7 100644 --- a/book/src/03_ticket_v1/04_visibility.md +++ b/book/src/03_ticket_v1/04_visibility.md @@ -43,4 +43,3 @@ pub struct Configuration { `Configuration` is public, but you can only access the `version` field from within the same crate. The `active` field, instead, is private and can only be accessed from within the same module or one of its submodules. - diff --git a/book/src/03_ticket_v1/07_setters.md b/book/src/03_ticket_v1/07_setters.md index 7303122..81a81f2 100644 --- a/book/src/03_ticket_v1/07_setters.md +++ b/book/src/03_ticket_v1/07_setters.md @@ -106,4 +106,3 @@ ticket.set_title("New title".into()); ticket.set_description("New description".into()); ticket.set_status("In Progress".into()); ``` - diff --git a/book/src/03_ticket_v1/12_outro.md b/book/src/03_ticket_v1/12_outro.md index 8da9e57..52dd64c 100644 --- a/book/src/03_ticket_v1/12_outro.md +++ b/book/src/03_ticket_v1/12_outro.md @@ -3,4 +3,3 @@ We've covered a lot of foundational Rust concepts in this chapter.\ Before moving on, let's go through one last exercise to consolidate what we've learned. You'll have minimal guidance this time—just the exercise description and the tests to guide you. - diff --git a/book/src/04_traits/00_intro.md b/book/src/04_traits/00_intro.md index adead4e..47ec5c8 100644 --- a/book/src/04_traits/00_intro.md +++ b/book/src/04_traits/00_intro.md @@ -18,4 +18,3 @@ On top of traits as a concept, we'll also cover some of the key traits that are Since we'll be talking about conversions, we'll seize the opportunity to plug some of the "knowledge gaps" from the previous chapter—e.g. what is `"A title"`, exactly? Time to learn more about slices too! - diff --git a/book/src/04_traits/03_operator_overloading.md b/book/src/04_traits/03_operator_overloading.md index 0aba3a5..d963de1 100644 --- a/book/src/04_traits/03_operator_overloading.md +++ b/book/src/04_traits/03_operator_overloading.md @@ -96,4 +96,3 @@ impl PartialEq for MyType { } } ``` - diff --git a/book/src/04_traits/05_trait_bounds.md b/book/src/04_traits/05_trait_bounds.md index a9f4944..01bf8d3 100644 --- a/book/src/04_traits/05_trait_bounds.md +++ b/book/src/04_traits/05_trait_bounds.md @@ -170,4 +170,3 @@ The rationale is the same as for [explicit type annotations on function paramete each function signature is a contract between the caller and the callee, and the terms must be explicitly stated. This allows for better error messages, better documentation, less unintentional breakages across versions, and faster compilation times. - diff --git a/book/src/04_traits/06_str_slice.md b/book/src/04_traits/06_str_slice.md index 575cc45..e957e3d 100644 --- a/book/src/04_traits/06_str_slice.md +++ b/book/src/04_traits/06_str_slice.md @@ -114,4 +114,3 @@ If a method returns a `&String`, you're promising that there is heap-allocated U **matches exactly** the one you're returning a reference to.\ If a method returns a `&str`, instead, you have a lot more freedom: you're just saying that _somewhere_ there's a bunch of text data and that a subset of it matches what you need, therefore you're returning a reference to it. - diff --git a/book/src/04_traits/07_deref.md b/book/src/04_traits/07_deref.md index c70c95a..9b65664 100644 --- a/book/src/04_traits/07_deref.md +++ b/book/src/04_traits/07_deref.md @@ -89,4 +89,3 @@ Automatically converting types can make the code harder to read and understand. is defined on both `T` and `U`, which one will be called? We'll examine later in the course the "safest" use cases for deref coercion: smart pointers. - diff --git a/book/src/04_traits/08_sized.md b/book/src/04_traits/08_sized.md index 7ff8054..585b4c6 100644 --- a/book/src/04_traits/08_sized.md +++ b/book/src/04_traits/08_sized.md @@ -77,4 +77,3 @@ All the types we've seen so far are `Sized`: `u32`, `String`, `bool`, etc. `str`, as we just saw, is not `Sized`.\ `&str` is `Sized` though! We know its size at compile time: two `usize`s, one for the pointer and one for the length. - diff --git a/book/src/04_traits/09_from.md b/book/src/04_traits/09_from.md index 7800399..2d5dd67 100644 --- a/book/src/04_traits/09_from.md +++ b/book/src/04_traits/09_from.md @@ -138,4 +138,3 @@ In most cases, the target type is either: - Specified in the variable declaration with a type annotation (e.g. `let title: String = "A title".into();`) `.into()` will work out of the box as long as the compiler can infer the target type from the context without ambiguity. - diff --git a/book/src/04_traits/11_clone.md b/book/src/04_traits/11_clone.md index 404e836..b646bf6 100644 --- a/book/src/04_traits/11_clone.md +++ b/book/src/04_traits/11_clone.md @@ -105,4 +105,3 @@ struct MyType { The compiler implements `Clone` for `MyType` as you would expect: it clones each field of `MyType` individually and then constructs a new `MyType` instance using the cloned fields.\ Remember that you can use `cargo expand` (or your IDE) to explore the code generated by `derive` macros. - diff --git a/book/src/04_traits/12_copy.md b/book/src/04_traits/12_copy.md index d9b18dd..f51778e 100644 --- a/book/src/04_traits/12_copy.md +++ b/book/src/04_traits/12_copy.md @@ -111,4 +111,3 @@ struct MyStruct { field: u32, } ``` - diff --git a/book/src/04_traits/13_drop.md b/book/src/04_traits/13_drop.md index 2fdc251..2f4219a 100644 --- a/book/src/04_traits/13_drop.md +++ b/book/src/04_traits/13_drop.md @@ -50,4 +50,3 @@ error[E0184]: the trait `Copy` cannot be implemented for this type; the type has 2 | #[derive(Clone, Copy)] | ^^^^ `Copy` not allowed on types with destructors ``` - diff --git a/book/src/04_traits/14_outro.md b/book/src/04_traits/14_outro.md index 3504b49..838ab1e 100644 --- a/book/src/04_traits/14_outro.md +++ b/book/src/04_traits/14_outro.md @@ -25,4 +25,3 @@ A few guidelines to keep in mind: Before moving on, let's go through one last exercise to consolidate what we've learned. You'll have minimal guidance this time—just the exercise description and the tests to guide you. - diff --git a/book/src/05_ticket_v2/00_intro.md b/book/src/05_ticket_v2/00_intro.md index 2a71c42..2b06400 100644 --- a/book/src/05_ticket_v2/00_intro.md +++ b/book/src/05_ticket_v2/00_intro.md @@ -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 - diff --git a/book/src/05_ticket_v2/01_enum.md b/book/src/05_ticket_v2/01_enum.md index 6f665c0..6fa9657 100644 --- a/book/src/05_ticket_v2/01_enum.md +++ b/book/src/05_ticket_v2/01_enum.md @@ -41,4 +41,3 @@ enum Status { ``` `enum`, just like `struct`, defines **a new Rust type**. - diff --git a/book/src/05_ticket_v2/02_match.md b/book/src/05_ticket_v2/02_match.md index 6df9240..8541c7a 100644 --- a/book/src/05_ticket_v2/02_match.md +++ b/book/src/05_ticket_v2/02_match.md @@ -68,4 +68,3 @@ match status { ``` The `_` pattern matches anything that wasn't matched by the previous patterns. - diff --git a/book/src/05_ticket_v2/03_variants_with_data.md b/book/src/05_ticket_v2/03_variants_with_data.md index 55d9ffb..ae47e08 100644 --- a/book/src/05_ticket_v2/03_variants_with_data.md +++ b/book/src/05_ticket_v2/03_variants_with_data.md @@ -86,4 +86,3 @@ match status { } } ``` - diff --git a/book/src/05_ticket_v2/04_if_let.md b/book/src/05_ticket_v2/04_if_let.md index 05abcd4..a8cd49a 100644 --- a/book/src/05_ticket_v2/04_if_let.md +++ b/book/src/05_ticket_v2/04_if_let.md @@ -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. - diff --git a/book/src/05_ticket_v2/05_nullability.md b/book/src/05_ticket_v2/05_nullability.md index b8ddf6e..db4f282 100644 --- a/book/src/05_ticket_v2/05_nullability.md +++ b/book/src/05_ticket_v2/05_nullability.md @@ -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. - diff --git a/book/src/05_ticket_v2/06_fallibility.md b/book/src/05_ticket_v2/06_fallibility.md index 1781f72..d3b4c37 100644 --- a/book/src/05_ticket_v2/06_fallibility.md +++ b/book/src/05_ticket_v2/06_fallibility.md @@ -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. - diff --git a/book/src/05_ticket_v2/07_unwrap.md b/book/src/05_ticket_v2/07_unwrap.md index 8786d75..cb793ba 100644 --- a/book/src/05_ticket_v2/07_unwrap.md +++ b/book/src/05_ticket_v2/07_unwrap.md @@ -38,4 +38,3 @@ When you call a function that returns a `Result`, you have two key options: Err(err) => eprintln!("Error: {}", err), } ``` - diff --git a/book/src/05_ticket_v2/08_error_enums.md b/book/src/05_ticket_v2/08_error_enums.md index d4452fa..d9ac83c 100644 --- a/book/src/05_ticket_v2/08_error_enums.md +++ b/book/src/05_ticket_v2/08_error_enums.md @@ -36,4 +36,3 @@ match s.parse_u32() { } } ``` - diff --git a/book/src/05_ticket_v2/09_error_trait.md b/book/src/05_ticket_v2/09_error_trait.md index 66f1777..77f39fc 100644 --- a/book/src/05_ticket_v2/09_error_trait.md +++ b/book/src/05_ticket_v2/09_error_trait.md @@ -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. - diff --git a/book/src/05_ticket_v2/10_packages.md b/book/src/05_ticket_v2/10_packages.md index ab4d13d..dc0ef51 100644 --- a/book/src/05_ticket_v2/10_packages.md +++ b/book/src/05_ticket_v2/10_packages.md @@ -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 ``` - diff --git a/book/src/05_ticket_v2/11_dependencies.md b/book/src/05_ticket_v2/11_dependencies.md index e325e18..b0defb6 100644 --- a/book/src/05_ticket_v2/11_dependencies.md +++ b/book/src/05_ticket_v2/11_dependencies.md @@ -52,4 +52,3 @@ static_assertions = "1.1.0" ``` We've been using a few of these throughout the book to shorten our tests. - diff --git a/book/src/05_ticket_v2/12_thiserror.md b/book/src/05_ticket_v2/12_thiserror.md index 22d3d36..2c3af65 100644 --- a/book/src/05_ticket_v2/12_thiserror.md +++ b/book/src/05_ticket_v2/12_thiserror.md @@ -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. - diff --git a/book/src/05_ticket_v2/13_try_from.md b/book/src/05_ticket_v2/13_try_from.md index dac28d5..3887eb3 100644 --- a/book/src/05_ticket_v2/13_try_from.md +++ b/book/src/05_ticket_v2/13_try_from.md @@ -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. - diff --git a/book/src/05_ticket_v2/14_source.md b/book/src/05_ticket_v2/14_source.md index 8c18480..3e8a30f 100644 --- a/book/src/05_ticket_v2/14_source.md +++ b/book/src/05_ticket_v2/14_source.md @@ -148,4 +148,3 @@ fn read_file() -> Result { 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) -