Skip to content

Commit 1aa1d7b

Browse files
authored
More stream-2025-04-16.md.
1 parent 0285b98 commit 1aa1d7b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

stream-2025-04-16.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,13 @@ fn main() {
110110
}
111111
```
112112

113-
Polymorphic type and `Into<T>`: [link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=70746dda53fe77e47ea1c8f68e6ef169).
113+
Polymorphic type and `Into<T>`: [link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=6e83d0668f7734f455e5b90980d791f9).
114114

115115
```rust
116+
#![allow(unused_variables)]
117+
#![allow(unused_assignments)]
118+
119+
#[derive(Debug)]
116120
struct DontPanic;
117121

118122
fn do_not_panic() -> DontPanic { DontPanic }
@@ -136,7 +140,22 @@ fn print_int<T: Into<i32>>(val: T) {
136140
}
137141

138142
fn main() {
143+
// This works.
139144
print_string(do_not_panic());
140145
print_int(do_not_panic());
146+
147+
// Can do this btw!
148+
let mut v = Vec::new();
149+
v.push(do_not_panic().into());
150+
v.push(do_not_panic().into());
151+
v.push(do_not_panic()); // But at least one must specify the actual type!
152+
println!("{:?}", v);
153+
154+
// Same with Option: either at least one proper assignment, or explicit type spec.
155+
let mut o: Option<_> = None;
156+
o = None;
157+
o = None;
158+
o = Some(true); // Need either this assignment or an explicit type annotation.
159+
o = None;
141160
}
142161
```

0 commit comments

Comments
 (0)