Formatter
This commit is contained in:
@@ -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!
|
||||
|
||||
|
||||
@@ -96,4 +96,3 @@ impl PartialEq for MyType {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -111,4 +111,3 @@ struct MyStruct {
|
||||
field: u32,
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user