Skip to content

Instantly share code, notes, and snippets.

@igor04
Created September 16, 2014 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igor04/eb559fa1ed63d3d082bf to your computer and use it in GitHub Desktop.
Save igor04/eb559fa1ed63d3d082bf to your computer and use it in GitHub Desktop.
attributes.rs
//
// #[item_attribute] - attribute for module or file
//
// #![crate_attribute] - attribute for crate
//
// - #[attribute = "value"]
// - #[attribute(key = "value")]
// - #[attribute(value)]
//
// #![crate_type = "lib"] - crate as library (instead `--crate-type` compile param)
// #![crate_name = "something"] - library is named "something"
//
#[cfg(target_os = "linux")]
fn are_you_on_linux() {
println!("you are running linux!")
}
#[cfg(not(target_os = "linux"))]
fn are_you_on_linux() {
println!("you are *not* running linux!")
}
#[cfg(not(some_key))]
fn conditional_function() {
println!("you don't pass `--cfg some_key`!")
}
#[cfg(some_key)]
fn conditional_function() {
println!("you just pass `--cfg some_key`!")
}
// allow unused code
#[allow(dead_code)]
// allow camel case type names
#[allow(non_camel_case_types)]
// add default Show trait implementation to struct
#[deriving(Show)]
struct SomeStructure (int, int);
fn main() {
are_you_on_linux();
conditional_function();
println!("test deriving Show - {}", SomeStructure(1,2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment