pub trait Camera: Send + Sync {
// Required methods
fn start(&self) -> Result<(), CameraError>;
fn stop(&self);
// Provided methods
fn request_still(&self) -> Result<(), CameraError> { ... }
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 platform capture session.
A backend starts and stops the device and publishes what it produces through
publish_camera_frame and publish_camera_state; nothing here is
polled, and no method blocks for the length of a capture.
Required Methods§
Sourcefn start(&self) -> Result<(), CameraError>
fn start(&self) -> Result<(), CameraError>
Opens the session.
Returns as soon as the request is accepted. The session’s progress
arrives as CameraState, because opening a camera takes long enough
on a phone that a screen has to show something in the meantime.
Provided Methods§
Sourcefn request_still(&self) -> Result<(), CameraError>
fn request_still(&self) -> Result<(), CameraError>
Asks for a full-resolution still.
The picture arrives through publish_camera_still, because the device
takes as long as it takes to expose and encode, and a call that blocked
for it would block whatever asked.
Sourcefn set_torch(&self, _on: bool) -> bool
fn set_torch(&self, _on: bool) -> bool
Turns the torch on or off while the session runs.
Scanner-style applications light a dim scene rather than analysing
photon-starved frames. Returns false where the device has no torch;
the torch dies with the session.
Sourcefn lenses(&self) -> Vec<CameraLens>
fn lenses(&self) -> Vec<CameraLens>
The devices the application may pick between, back cameras first and in field-of-view order, widest first, then the rest.
An empty list means the application shows no lens control: either the
platform has one camera or the backend does not list them. Backends
also publish this through publish_camera_lenses when a session
opens, so a screen observes rememberCameraLenses rather than paying
this blocking platform call per recomposition.
Sourcefn lens(&self) -> Option<String>
fn lens(&self) -> Option<String>
The device the session is using, or None when nothing is open and the
backend has no stored choice.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".