book: update cross platform code samples

Our original code sample was missing some elements in the use statements
that clarified how modules were organized with sys.

BUG=none
TEST=n/a

Change-Id: I62d6a294218fa7c9c5853dbefc6550de763e7c8e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3614852
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
This commit is contained in:
Noah Gold 2022-04-28 13:26:56 -07:00 committed by Chromeos LUCI
parent 55a5b54bf2
commit fdd42b7b0e

View file

@ -396,12 +396,14 @@ File: `sys.rs`
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(unix)] { if #[cfg(unix)] {
pub mod unix; pub mod unix;
pub use self::unix::print_hello; use unix as platform;
} else if #[cfg(windows)] { } else if #[cfg(windows)] {
pub mod windows; pub mod windows;
pub use self::windows::print_hello; use windows as platform;
} }
} }
pub use platform::print;
``` ```
File: `unix.rs` File: `unix.rs`
@ -434,16 +436,16 @@ The user of the library, say mylib, now has to do something like below which mak
the functions `print_u8` and `print_u16` are platform specific. the functions `print_u8` and `print_u16` are platform specific.
```rust ```rust
use mylib::print_hello; use mylib::sys::print;
fn my_print() { fn my_print() {
print_hello(); print();
#[cfg(unix)] #[cfg(unix)]
mylib::unix::print_u8(1); mylib::sys::unix::print_u8(1);
#[cfg(windows)] #[cfg(windows)]
mylib::windows::print_u16(1); mylib::sys::windows::print_u16(1);
} }
``` ```