Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,21 @@
|
|||
// This function will only be compiled if we are compiling on Linux
|
||||
#[cfg(target_os = "linux")]
|
||||
fn running_linux() {
|
||||
println!("This is linux");
|
||||
}
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn running_linux() {
|
||||
println!("This is not linux");
|
||||
}
|
||||
|
||||
// If we are on linux, we must be using glibc
|
||||
#[cfg_attr(target_os = "linux", target_env = "gnu")]
|
||||
// We must either be compiling for ARM or on a little endian machine that doesn't have 32-bit pointers pointers, on a
|
||||
// UNIX like OS and only if we are doing a test build
|
||||
#[cfg(all(
|
||||
any(target_arch = "arm", target_endian = "little"),
|
||||
not(target_pointer_width = "32"),
|
||||
unix,
|
||||
test
|
||||
))]
|
||||
fn highly_specific_function() {}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
fn main() {
|
||||
if cfg!(target_os = "linux") {
|
||||
// Do something
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
trait PrintType {
|
||||
fn print_type(&self);
|
||||
}
|
||||
|
||||
impl PrintType for char {
|
||||
fn print_type(&self) {
|
||||
println!("char");
|
||||
}
|
||||
}
|
||||
|
||||
impl PrintType for f64 {
|
||||
fn print_type(&self) {
|
||||
println!("64-bit float");
|
||||
}
|
||||
}
|
||||
|
||||
fn prints_type_of_args<T, U>(arg1: &T, arg2: &U)
|
||||
where T: PrintType,
|
||||
U: PrintType
|
||||
{
|
||||
arg1.print_type();
|
||||
arg2.print_type();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
prints_type_of_args(&'a', &2.0);
|
||||
prints_type_of_args(&'a', &'b');
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
if some_conditional {
|
||||
do_stuff();
|
||||
} else if some_other_conditional {
|
||||
do_other_stuff();
|
||||
} else {
|
||||
destroy_humanity();
|
||||
}
|
||||
|
||||
// If statements are also expressions and will yield the value of the last expression in each block
|
||||
let x = if y > z { y + 1 } else { z * 4 };
|
||||
|
||||
// Pattern matching may also be used
|
||||
struct Point {
|
||||
x: i32,
|
||||
y: i32,
|
||||
}
|
||||
fn some_function(p: Option<Point>) {
|
||||
if let Some(Point { x: x_coord, y: y_coord }) = p {
|
||||
// Do something with x_coord and y_coord
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
fn some_other_function(p: Option<Point>) {
|
||||
match p {
|
||||
Some(Point { x: 0, y: 0 }) => println!("Point is on origin"),
|
||||
Some(Point { x: 0, y: _ }) | Some(Point { x: _, y: 0 }) => println!("Point is on an axis"),
|
||||
Some(Point {x: a, y: b}) if a == b => println!("x and y are the same value"),
|
||||
Some(Point {x: ref mut a, y: ref b}) if *a > 4 && *b < 2 => println!("we got a mutable reference to x-value and an immutable reference to y-value."),
|
||||
op @ Some(p) => println!("op is the Option<Point> while p is the contained Point"),
|
||||
None => println!("We didn't get a point"),
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fn prints_args_dynamic(arg1: &PrintType, arg2: &PrintType) {
|
||||
arg1.print_type();
|
||||
arg2.print_type();
|
||||
}
|
||||
fn main() {
|
||||
prints_args_dynamic(&'a', &2.0);
|
||||
prints_args_dynamic(&6.3,&'c');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue