From fdd42b7b0e325f4663ce038a390cef440f0ed56c Mon Sep 17 00:00:00 2001 From: Noah Gold Date: Thu, 28 Apr 2022 13:26:56 -0700 Subject: [PATCH] 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 Tested-by: kokoro Commit-Queue: Noah Gold Reviewed-by: Vikram Auradkar --- .../style_guide_platform_specific_code.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/book/src/contributing/style_guide_platform_specific_code.md b/docs/book/src/contributing/style_guide_platform_specific_code.md index 9f12b30e92..9cd8436604 100644 --- a/docs/book/src/contributing/style_guide_platform_specific_code.md +++ b/docs/book/src/contributing/style_guide_platform_specific_code.md @@ -396,12 +396,14 @@ File: `sys.rs` cfg_if::cfg_if! { if #[cfg(unix)] { pub mod unix; - pub use self::unix::print_hello; + use unix as platform; } else if #[cfg(windows)] { pub mod windows; - pub use self::windows::print_hello; + use windows as platform; } } + +pub use platform::print; ``` 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. ```rust -use mylib::print_hello; +use mylib::sys::print; fn my_print() { - print_hello(); + print(); #[cfg(unix)] - mylib::unix::print_u8(1); + mylib::sys::unix::print_u8(1); #[cfg(windows)] - mylib::windows::print_u16(1); + mylib::sys::windows::print_u16(1); } ```