Move is the default in Rust
This commit is contained in:
parent
019fbcf095
commit
823ec0ad00
29
src/main.rs
29
src/main.rs
@ -1,14 +1,23 @@
|
||||
fn add_10(value: Option<u32>) -> Result<u32, String> {
|
||||
match value {
|
||||
Some(v) => Ok(v + 10),
|
||||
None => Err(String::from("value was empty")),
|
||||
struct Vector3 {
|
||||
x: f32,
|
||||
y: f32,
|
||||
z: f32,
|
||||
}
|
||||
|
||||
impl Vector3 {
|
||||
pub fn new(x: f32, y: f32, z: f32) -> Vector3 {
|
||||
Vector3 { x, y, z }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let value = add_10(None);
|
||||
|
||||
println!("Result is: {}", value.unwrap_or(42));
|
||||
|
||||
panic!("Non recoverable error.");
|
||||
fn print(vec: Vector3) {
|
||||
println!("Vector3( x = {}, y = {}, z = {})", vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut vec = Vector3::new(1.0, 0.0, 0.0);
|
||||
|
||||
print(vec);
|
||||
|
||||
vec.y = 2.0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user