Skip to content

Commit b18a8c3

Browse files
committed
strings4: remove From-based conversion
To understand From-based conversion, an understanding of traits is required, which we teach in a later chapter. The From trait specifically is taught in one of the conversion exercises. So, we can safely remove it here without users missing out on learning something important. A specific source of confusion for users was a warning that the conversion is useless, which appeared when using the `string_slice` function for the expression with `.into()`. closes #2190
1 parent 60b369a commit b18a8c3

2 files changed

Lines changed: 0 additions & 11 deletions

File tree

exercises/09_strings/strings4.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ fn main() {
2121

2222
placeholder("rust is fun!".to_owned());
2323

24-
placeholder("nice weather".into());
25-
2624
placeholder(format!("Interpolation {}", "Station"));
2725

2826
// WARNING: This is byte indexing, not character indexing.

solutions/09_strings/strings4.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ fn main() {
1515

1616
string("rust is fun!".to_owned());
1717

18-
// Here, both answers work.
19-
// `.into()` converts a type into an expected type.
20-
// If it is called where `String` is expected, it will convert `&str` to `String`.
21-
string("nice weather".into());
22-
// But if it is called where `&str` is expected, then `&str` is kept as `&str` since no conversion is needed.
23-
// If you remove the `#[allow(…)]` line, then Clippy will tell you to remove `.into()` below since it is a useless conversion.
24-
#[allow(clippy::useless_conversion)]
25-
string_slice("nice weather".into());
26-
2718
string(format!("Interpolation {}", "Station"));
2819

2920
// WARNING: This is byte indexing, not character indexing.

0 commit comments

Comments
 (0)