Example with ownership
This commit is contained in:
parent
07d7855f47
commit
81205e5b29
18
src/main.rs
18
src/main.rs
@ -69,19 +69,23 @@ impl<'a> Container<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn foo<'a>(image: Image) -> Container<'a> {
|
||||
Container::new(image.get(0, 0))
|
||||
fn brighter<'a>(a: &'a RGB, b: &'a RGB) -> &'a RGB {
|
||||
if a.red / 3 + a.green / 3 + a.blue / 3 > b.red / 3 + b.green / 3 + b.blue / 3 {
|
||||
a
|
||||
} else {
|
||||
b
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let image = Image::white_image(640, 480);
|
||||
|
||||
let c = image.get(0, 0);
|
||||
let black = RGB::black();
|
||||
|
||||
let container = Container::new(c);
|
||||
let c1 = image.get(0, 0);
|
||||
//let c2 = image.get(1, 1);
|
||||
|
||||
let container1 = foo(image);
|
||||
let brightest = brighter(c1, &black);
|
||||
|
||||
println!("{}", container.value.blue);
|
||||
println!("{}", container1.value.blue);
|
||||
println!("{}", brightest.red);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user