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