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> {
|
fn brighter<'a>(a: &'a RGB, b: &'a RGB) -> &'a RGB {
|
||||||
Container::new(image.get(0, 0))
|
if a.red / 3 + a.green / 3 + a.blue / 3 > b.red / 3 + b.green / 3 + b.blue / 3 {
|
||||||
|
a
|
||||||
|
} else {
|
||||||
|
b
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let image = Image::white_image(640, 480);
|
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!("{}", brightest.red);
|
||||||
println!("{}", container1.value.blue);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user