File tree 1 file changed +18
-3
lines changed
1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -17,15 +17,30 @@ The `panic_handler` attribute can only be applied to a function with signature
17
17
Below is shown a ` panic_handler ` function that logs the panic message and then halts the
18
18
thread.
19
19
20
- ``` rust
20
+ <!-- NOTE(ignore) `mdbook test` doesn't support `no_std` code -->
21
+
22
+ ``` rust, ignore
21
23
#![no_std]
22
24
23
- use core :: intrinsics ;
25
+ use core::fmt::{self, Write} ;
24
26
use core::panic::PanicInfo;
25
27
28
+ struct Sink {
29
+ // ..
30
+ # _0: (),
31
+ }
32
+ #
33
+ # impl Sink {
34
+ # fn new() -> Sink { Sink { _0: () }}
35
+ # }
36
+ #
37
+ # impl fmt::Write for Sink {
38
+ # fn write_str(&mut self, _: &str) -> fmt::Result { Ok(()) }
39
+ # }
40
+
26
41
#[panic_handler]
27
42
fn panic(info: &PanicInfo) -> ! {
28
- let mut sink = /* .. */ ;
43
+ let mut sink = Sink::new() ;
29
44
30
45
// logs "panicked at '$reason', src/main.rs:27:4" to some `sink`
31
46
let _ = writeln!(sink, "{}", info);
You can’t perform that action at this time.
0 commit comments