File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -420,7 +420,7 @@ fn main() {
420420```
421421
422422Alternatively, 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
424424them.
425425
426426``` no_run
@@ -436,12 +436,19 @@ extern {
436436
437437fn main() {
438438 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+ }
442446}
443447```
444448
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+
445452# Foreign calling conventions
446453
447454Most 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