June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,21 +1,21 @@
|
|||
trait PrintType {
|
||||
fn print_type();
|
||||
fn print_type(&self);
|
||||
}
|
||||
|
||||
impl PrintType for char {
|
||||
fn print_type() {
|
||||
fn print_type(&self) {
|
||||
println!("char");
|
||||
}
|
||||
}
|
||||
|
||||
impl PrintType for f64 {
|
||||
fn print_type() {
|
||||
fn print_type(&self) {
|
||||
println!("64-bit float");
|
||||
}
|
||||
}
|
||||
|
||||
fn prints_type_of_args<T,U>(arg1: T, arg2: U)
|
||||
where T: PrintType
|
||||
fn prints_type_of_args<T, U>(arg1: &T, arg2: &U)
|
||||
where T: PrintType,
|
||||
U: PrintType
|
||||
{
|
||||
arg1.print_type();
|
||||
|
|
@ -23,6 +23,6 @@ fn prints_type_of_args<T,U>(arg1: T, arg2: U)
|
|||
}
|
||||
|
||||
fn main() {
|
||||
prints_type_of_args('a', 2.0);
|
||||
prints_type_of_args('a', 'b');
|
||||
prints_type_of_args(&'a', &2.0);
|
||||
prints_type_of_args(&'a', &'b');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
if some_conditional {
|
||||
do_stuff();
|
||||
} else if some_other_conditional
|
||||
} else if some_other_conditional {
|
||||
do_other_stuff();
|
||||
} else {
|
||||
destroy_humanity();
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ 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 x > 4 && y < 2 => println!("we got a mutable reference to x-value and an immutable reference to y-value."),
|
||||
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"),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue