Compare commits

...

5 Commits

Author SHA1 Message Date
Fangyi Zhou
d5f407d720 Fix a typo in 03_ticket_v1/08_stack (#19)
The type argument of `size_of` is `<u8>` instead of `<String>`.
2024-05-18 17:57:02 +02:00
taohua
44f3260fbe misunderstand the implements verb (#18)
* Update 08_from.md

* test

* Update exercises/04_traits/08_from/src/lib.rs

---------

Co-authored-by: datewu <hihahajun@gmail.com>
Co-authored-by: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com>
2024-05-18 17:56:39 +02:00
Loup Federico
1d9ba4c25c Fix typo in 05_ticket_v2/09_error_trait/[...] instructions (#13)
The commented instructions of the exercise ask to use `No description provided` for the description field when calling `easy_ticket` with an invalid description argument. However, the unit test of that behavior compares the description to `Description not provided` instead.

Previous exercises in that part also use `Description not provided`.

Update the exercise 05_ticket_v2/09_error_trait instructions to use `Description not provided` as an expected default  description value when calling `easy_ticket` with no description instead of `No description provided`.
2024-05-18 17:54:50 +02:00
Thanos
8c3ef6cb51 fix spelling error (#11) 2024-05-18 17:54:24 +02:00
Loup Federico
f2865b25db Fix typo in 10_clone.md illustration (#10)
The clone() illustration shows two `s` values in the stack when one of them is the original `s` value which got cloned and the other one should be the new `t` value created from `s`.

Rename the second value from `s` to `t`.
2024-05-18 12:03:05 +02:00
6 changed files with 9 additions and 9 deletions

View File

@@ -30,7 +30,7 @@ while i <= 5 {
}
```
This will keep adding 1 to `sum` until `i` is no longer less than or equal to 5.
This will keep adding 1 to `i` and `i` to `sum` until `i` is no longer less than or equal to 5.
## The `mut` keyword
@@ -86,4 +86,4 @@ This will compile and run without errors.
## Further reading
- [`while` loop documentation](https://doc.rust-lang.org/std/keyword.while.html)
- [`while` loop documentation](https://doc.rust-lang.org/std/keyword.while.html)

View File

@@ -45,7 +45,7 @@ using the [`std::mem::size_of`](https://doc.rust-lang.org/std/mem/fn.size_of.htm
For a `u8`, for example:
```rust
// We'll explain this funny-looking syntax (`::<String>`) later on.
// We'll explain this funny-looking syntax (`::<u8>`) later on.
// Ignore it for now.
assert_eq!(std::mem::size_of::<u8>(), 1);
```
@@ -59,4 +59,4 @@ assert_eq!(std::mem::size_of::<u8>(), 1);
[^stack-overflow]: If you have nested function calls, each function pushes its data onto the stack when it's called but
it doesn't pop it off until the innermost function returns.
If you have too many nested function calls, you can run out of stack space—the stack is not infinite!
That's called a [**stack overflow**](https://en.wikipedia.org/wiki/Stack_overflow).
That's called a [**stack overflow**](https://en.wikipedia.org/wiki/Stack_overflow).

View File

@@ -105,7 +105,7 @@ though the former bound is implicit.
In [`std`'s documentation](https://doc.rust-lang.org/std/convert/trait.From.html#implementors)
you can see which `std` types implement the `From` trait.
You'll find that `&str` implements `From<&str> for String`. Thus, we can write:
You'll find that `String` implements `From<&str> for String`. Thus, we can write:
```rust
let title = String::from("A title");
@@ -129,7 +129,7 @@ where
}
```
If a type `T` implements `From<U>`, then `Into<U> for T` is automatically implemented. That's why
If a type `U` implements `From<T>`, then `Into<U> for T` is automatically implemented. That's why
we can write `let title = "A title".into();`.
## `.into()`

View File

@@ -75,7 +75,7 @@ Heap: | H | e | l | l | o |
When `let t = s.clone()` is executed, a whole new region is allocated on the heap to store a copy of the data:
```text
s s
s t
+---------+--------+----------+ +---------+--------+----------+
Stack | pointer | length | capacity | | pointer | length | capacity |
| | | 5 | 5 | | | | 5 | 5 |

View File

@@ -1,4 +1,4 @@
// TODO: Implement the `From` trait for the `u32` type to make `example` compile.
// TODO: Implement the `From` trait for the `WrappingU32` type to make `example` compile.
pub struct WrappingU32 {
value: u32,

View File

@@ -11,7 +11,7 @@ enum TicketNewError {
// TODO: `easy_ticket` should panic when the title is invalid, using the error message
// stored inside the relevant variant of the `TicketNewError` enum.
// When the description is invalid, instead, it should use a default description:
// "No description provided".
// "Description not provided".
fn easy_ticket(title: String, description: String, status: Status) -> Ticket {
todo!()
}