lit-robotics / libcamera-rs

Experimental Rust bindings for libcamera
Apache License 2.0
46 stars 15 forks source link

enable `rust_2018_idoms`-lint as warning and fix issues #13

Closed markus-k closed 1 year ago

markus-k commented 1 year ago

as extensively discussed in rust-lang/rust#91639, elided lifetimes in paths should be visible and can lead to confusion if they are omitted. The rust_2018_idoms warning should therefore generally be enabled at crate-level.

An example is something like

struct SimpleCamera<'a> {
    camera: ActiveCamera<'a>,
}

impl<'a> SimpleCamera<'a> {
    fn new() -> anyhow::Result<Self> {
        let manager = CameraManager::new()?;

        let cameras = manager.cameras();
        let camera = cameras.get(0).unwrap();

        let active_camera = camera.acquire()?;

        Ok(Self {
            camera: active_camera,
        })
    }
}

where you might confused why this isn't working, only looking at the return types of CameraManager::cameras() and Camera::acquire() (which suggest that you get a completely owned value, i.e. no lifetimes and references).

This PR is gonna clash with #6, so I guess #6 should be merged first.

chemicstry commented 1 year ago

Thanks!

I will fix #6 later