pub trait Camera: Send + Sync {
// Required methods
fn start(&self) -> Result<String, CameraError>;
fn latest_frame(&self) -> Option<CameraFrame>;
fn stop(&self);
// Provided methods
fn capture_still(&self) -> Option<CameraStill> { ... }
fn set_torch(&self, _on: bool) -> bool { ... }
fn lenses(&self) -> Vec<CameraLens> { ... }
fn lens(&self) -> Option<String> { ... }
fn use_lens(&self, _id: &str) -> bool { ... }
fn has_flash(&self) -> bool { ... }
fn set_flash(&self, _mode: FlashMode) -> bool { ... }
}Expand description
A running (or startable) live camera. Implementations are Send + Sync so a
background preview pump can start/stop and poll frames off the UI thread.
Required Methods§
Sourcefn start(&self) -> Result<String, CameraError>
fn start(&self) -> Result<String, CameraError>
Start the capture session, returning a human-readable device name. Safe to call again while already running (idempotent).
Sourcefn latest_frame(&self) -> Option<CameraFrame>
fn latest_frame(&self) -> Option<CameraFrame>
The most recent frame, or None if none has arrived yet.
Provided Methods§
Sourcefn capture_still(&self) -> Option<CameraStill>
fn capture_still(&self) -> Option<CameraStill>
Capture a full-resolution still through the platform photo pipeline.
Blocks up to a few seconds while the device exposes and encodes.
Returns None where the backend has no dedicated photo path (callers
should fall back to latest_frame) or when the
capture fails.
Sourcefn set_torch(&self, _on: bool) -> bool
fn set_torch(&self, _on: bool) -> bool
Toggle the capture device’s torch (flashlight) while the session runs.
Scanner-style apps light dim scenes instead of trying to analyze
photon-starved frames. Returns false where the device has no torch
or the backend has none wired; the torch dies with the session.
Sourcefn lenses(&self) -> Vec<CameraLens>
fn lenses(&self) -> Vec<CameraLens>
The capture devices the app may pick between, back cameras first and in field-of-view order (widest first). An empty list means the app shows no lens control: either the platform has one camera or the backend does not list them.
Sourcefn lens(&self) -> Option<String>
fn lens(&self) -> Option<String>
The id of the device the session uses, or None when nothing is open
and the backend has no stored choice.
Sourcefn use_lens(&self, _id: &str) -> bool
fn use_lens(&self, _id: &str) -> bool
Open id instead of the current device, keeping the session running.
Returns false when the id is unknown or the backend cannot switch.
Sourcefn set_flash(&self, _mode: FlashMode) -> bool
fn set_flash(&self, _mode: FlashMode) -> bool
What the flash does on the next capture_still.
Returns false where the device has no flash or the backend has none
wired; the mode dies with the session.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".