Created
July 21, 2022 15:19
-
-
Save kalloc/e06c7584c0f67149f8feccf312838795 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Foo { | |
value: String, | |
} | |
impl Foo { | |
#[cfg(not(target_os = "macos"))] | |
fn xxx(&mut self) { | |
self.value.push_str(".not macOS.") | |
} | |
#[cfg(not(target_os = "linux"))] | |
fn xxx(&mut self) { | |
self.value.push_str(".not linux.") | |
} | |
pub fn call(&mut self) -> String { | |
self.xxx(); | |
self.value.clone() | |
} | |
} | |
fn main() { | |
println!("start"); | |
if cfg!(not(target_os = "macos")) { | |
println!("not macOS"); | |
} | |
if cfg!(not(target_os = "linux")) { | |
println!("not Linux"); | |
} | |
let mut foo = Foo { value: "str".to_string() }; | |
println!("> {}", foo.call()); | |
println!("end"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment