pub trait App: Send {
const NAME: &'static str;
// Required methods
fn run<'a>(&'a mut self) -> Pin<Box<dyn Future<Output = ()> + 'a>>;
fn can_run(registry: &Registry) -> bool
where Self: Sized;
fn new(registry: &mut Registry) -> Option<Self>
where Self: Sized;
fn release(self, registry: &mut Registry)
where Self: Sized;
}Expand description
An application that can be selected and run by the xpanse firmware.
can_run should mirror the resource set acquired by new, without mutating
the registry. After run completes, the platform passes the app to
release, which must return all of its resource leases.
Apps run on core 1, so any task spawned will also run core 1
Apps can use slint ui or direct video to show stuff on the screen
§Example
use std::{boxed::Box, future::Future, pin::Pin};
use xpanse_api::{
app::App,
registry::{Registry, ResourceLease},
};
struct StatusLed;
struct StatusApp {
led: ResourceLease<StatusLed>,
}
impl App for StatusApp {
const NAME: &'static str = "Status";
fn can_run(registry: &Registry) -> bool {
registry.has::<StatusLed>()
}
fn new(registry: &mut Registry) -> Option<Self> {
Some(Self { led: registry.take_resource()? })
}
fn run<'a>(&'a mut self) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
Box::pin(async move {
let _led = self.led.resource_mut();
// Drive the capability until the app decides to exit.
})
}
fn release(self, registry: &mut Registry) {
registry.return_resource(self.led);
}
}Required Associated Constants§
Required Methods§
Sourcefn run<'a>(&'a mut self) -> Pin<Box<dyn Future<Output = ()> + 'a>>
fn run<'a>(&'a mut self) -> Pin<Box<dyn Future<Output = ()> + 'a>>
Runs the app until it exits.
Resource leases held by self remain exclusive while this future is
alive. The returned future is not required to be Send.
Sourcefn can_run(registry: &Registry) -> boolwhere
Self: Sized,
fn can_run(registry: &Registry) -> boolwhere
Self: Sized,
Reports whether all resources required by this app are available.
This method must not mutate registry. Use
Registry::has_resource_set when the app needs several distinct
physical resources.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".