File tree 1 file changed +11
-4
lines changed
1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -420,7 +420,7 @@ fn main() {
420
420
```
421
421
422
422
Alternatively, you may need to alter global state provided by a foreign
423
- interface. To do this, statics can be declared with ` mut ` so rust can mutate
423
+ interface. To do this, statics can be declared with ` mut ` so we can mutate
424
424
them.
425
425
426
426
``` no_run
@@ -436,12 +436,19 @@ extern {
436
436
437
437
fn main() {
438
438
let prompt = CString::from_slice(b"[my-awesome-shell] $");
439
- unsafe { rl_prompt = prompt.as_ptr(); }
440
- // get a line, process it
441
- unsafe { rl_prompt = ptr::null(); }
439
+ unsafe {
440
+ rl_prompt = prompt.as_ptr();
441
+
442
+ println!("{}", rl_prompt);
443
+
444
+ rl_prompt = ptr::null();
445
+ }
442
446
}
443
447
```
444
448
449
+ Note that all interaction with a ` static mut ` is unsafe, both reading and
450
+ writing. Dealing with global mutable state requires a great deal of care.
451
+
445
452
# Foreign calling conventions
446
453
447
454
Most foreign code exposes a C ABI, and Rust uses the platform's C calling convention by default when
You can’t perform that action at this time.
0 commit comments