Compare commits
5 Commits
45c5e390c0
...
d5f407d720
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5f407d720 | ||
|
|
44f3260fbe | ||
|
|
1d9ba4c25c | ||
|
|
8c3ef6cb51 | ||
|
|
f2865b25db |
@@ -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)
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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()`
|
||||
|
||||
@@ -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 |
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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!()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user