Skip to content

Instantly share code, notes, and snippets.

@kalloc
Created July 21, 2022 15:19
Show Gist options
  • Save kalloc/e06c7584c0f67149f8feccf312838795 to your computer and use it in GitHub Desktop.
Save kalloc/e06c7584c0f67149f8feccf312838795 to your computer and use it in GitHub Desktop.
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