Example with ownership

This commit is contained in:
Stephan Rehfeld 2026-04-29 17:35:33 +02:00
parent 07d7855f47
commit 81205e5b29

View File

@ -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);
}