File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -124,7 +124,7 @@ impl fmt::Display for Wrapper {
124
124
}
125
125
}
126
126
127
- // alias for a lengthy type
127
+ // alias for a lengthy type. Note Fn vs fn.
128
128
type Thunk = Box < dyn Fn ( ) + Send + ' static > ;
129
129
130
130
fn takes_long_type ( f : Thunk ) {
@@ -185,8 +185,14 @@ fn main() {
185
185
let f: Thunk = Box :: new ( || println ! ( "aloha" ) ) ;
186
186
takes_long_type ( f) ;
187
187
returns_long_type ( ) ( ) ;
188
+
189
+ println ! ( "6) DST (Dynamically Sized Type): why str is always &str." ) ;
190
+ // str is a DST (dynamically sized type) and must use a pointer-like (&str slice)
191
+ let s1: & str = "Hellow there!" ;
192
+ let s2 = "How's it going?" ;
193
+ println ! ( "s1 is {s1}, s2 is {s2}." ) ;
188
194
189
- println ! ( "6 ) Never Type: loop/continue/panic! return ! (never type).
195
+ println ! ( "7 ) Never Type: loop/continue/panic! return ! (never type).
190
196
// break returns () (unit type)." ) ;
191
197
let mut c = 0 ;
192
198
//
@@ -198,16 +204,11 @@ fn main() {
198
204
break ;
199
205
}
200
206
} ;
201
- println ! ( "\n Press Ctrl+C after 3 secs to interrupt the following forever loop." ) ;
207
+ println ! ( "\n Press Ctrl+C to interrupt the following forever loop." ) ;
202
208
thread:: sleep ( Duration :: from_secs ( 3 ) ) ;
203
-
204
209
let b = loop {
205
210
c += 1 ;
206
211
print ! ( "bever " ) ;
207
212
} ;
208
213
209
- // str is a DST (dynamically sized type) and must use a pointer-like (&str slice)
210
- let s1: & str = "Hellow there!" ;
211
- let s2 = "How's it going?" ;
212
-
213
214
}
You can’t perform that action at this time.
0 commit comments