mirror of
https://github.com/Dhghomon/easy_rust
synced 2024-11-19 15:25:37 +00:00
deploy: d6c6442eaa
This commit is contained in:
parent
52fc6a5a16
commit
2eea6a943a
@ -1134,7 +1134,7 @@ The last country is Portugal inside the module rust_book::something::third_mod
|
||||
<p><code>cfg!</code></p>
|
||||
<p>We know that you can use attributes like <code>#[cfg(test)]</code> and <code>#[cfg(windows)]</code> to tell the compiler what to do in certain cases. When you have <code>test</code>, it will run the code when you run Rust under testing mode (if it's on your computer you type <code>cargo test</code>). And when you use <code>windows</code>, it will run the code if the user is using Windows. But maybe you just want to change one tiny bit of code depending on the operating system, etc. That's when this macro is useful. It returns a <code>bool</code>.</p>
|
||||
<pre><pre class="playground"><code class="language-rust">fn main() {
|
||||
let helpful_message = if cfg!(windows) { "backslash" } else { "slash" };
|
||||
let helpful_message = if cfg!(target_os = "windows") { "backslash" } else { "slash" };
|
||||
|
||||
println!(
|
||||
"...then in your hard drive, type the directory name followed by a {}. Then you...",
|
||||
|
@ -10751,7 +10751,7 @@ The last country is Portugal inside the module rust_book::something::third_mod
|
||||
<p><code>cfg!</code></p>
|
||||
<p>We know that you can use attributes like <code>#[cfg(test)]</code> and <code>#[cfg(windows)]</code> to tell the compiler what to do in certain cases. When you have <code>test</code>, it will run the code when you run Rust under testing mode (if it's on your computer you type <code>cargo test</code>). And when you use <code>windows</code>, it will run the code if the user is using Windows. But maybe you just want to change one tiny bit of code depending on the operating system, etc. That's when this macro is useful. It returns a <code>bool</code>.</p>
|
||||
<pre><pre class="playground"><code class="language-rust">fn main() {
|
||||
let helpful_message = if cfg!(windows) { "backslash" } else { "slash" };
|
||||
let helpful_message = if cfg!(target_os = "windows") { "backslash" } else { "slash" };
|
||||
|
||||
println!(
|
||||
"...then in your hard drive, type the directory name followed by a {}. Then you...",
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user