Skip to main content

App

Struct App 

Source
pub struct App<D: Document> { /* private fields */ }
Expand description

An app: name, document type and format, commands, views. run() opens the window; the same definition serves the CLI and MCP (App::cli) and tests (App::headless).

use ashlar_app::{App, Cx, Session};
use ashlar_command::{CommandError, CommandSpec};

#[derive(Clone, Default, serde::Serialize, serde::Deserialize)]
struct Doc { count: i64 }

fn bump(s: &mut Session<Doc>, _: &serde_json::Value) -> Result<serde_json::Value, CommandError> {
    s.edit("Bump", |d| d.count += 1);
    Ok(serde_json::Value::Null)
}

fn main() -> Result<(), ashlar_app::Error> {
    App::<Doc>::new("counter", "0.1.0")
        .command(CommandSpec::new("count.bump", "Bump", bump).menu(&["Edit"]).shortcut("Mod+B"))
        .view(|ui, cx: &mut Cx<'_, Doc>| {
            ui.label(format!("{}", cx.doc().count));
            if ui.button("Bump").clicked() {
                cx.dispatch("count.bump", serde_json::json!({}));
            }
        })
        .run()
}

Implementations§

Source§

impl<D: Document> App<D>

Source

pub fn new(name: impl Into<String>, version: impl Into<String>) -> Self

An app called name (lower case, used for folders, env vars and the CLI).

Source

pub fn organization( self, qualifier: impl Into<String>, org: impl Into<String>, ) -> Self

Reverse-domain qualifier and organisation for the OS folders ("com", "Acme").

Source

pub fn title(self, title: impl Into<String>) -> Self

Window title (default: the name).

Source

pub fn format(self, format: Format<D>) -> Self

The document’s file format, with its migrations.

Source

pub fn file_extension(self, ext: impl Into<String>) -> Self

A file extension offered by Open and Save dialogs (without the dot).

Source

pub fn commands( self, specs: impl IntoIterator<Item = CommandSpec<Session<D>>>, ) -> Self

Add commands (menus follow declaration order).

Source

pub fn command(self, spec: CommandSpec<Session<D>>) -> Self

Source

pub fn view(self, view: impl FnMut(&mut Ui, &mut Cx<'_, D>) + 'static) -> Self

The UI, drawn inside the window’s central area each frame.

Source

pub fn setup(self, f: impl FnOnce(&Context) + 'static) -> Self

Runs once before the first frame (install fonts, tokens).

Source

pub fn autosave(self, every: Option<Duration>) -> Self

Autosave interval (None: no autosave or recovery). Default 60 s.

Source

pub fn telemetry(self, key: impl Into<String>, endpoint: Option<&str>) -> Self

Telemetry (with the telemetry feature): write key and server. Always on when endpoint is set (no notice, no switches); TRACER_DISABLED in the environment turns it off.

Source

pub fn instructions(self, text: impl Into<String>) -> Self

What MCP clients are told about the app.

Source

pub fn dirs(self, dirs: AppDirs) -> Self

Put config, data, cache and logs here instead of the OS folders (tests, portable).

Source

pub fn window_size(self, width: f32, height: f32) -> Self

Source

pub fn control_port(self, port: u16) -> Self

Serve the control port on this port (also --control <port> and <APP>_CONTROL_PORT).

Source

pub fn headless(self) -> Headless<D>

A session without a window, driving the same commands (tests, scripts).

Source

pub fn runtime(self) -> Runtime<D>

The runtime without a window, for tests and benches: drive it with crate::Driver.

Source

pub fn cli(self) -> Cli

The app’s -cli binary: commands, exec, run, mcp, serve, version, each on a fresh headless session (or the running app with --connect PORT). Add app verbs to the returned ashlar_cli::Cli before run().

Source

pub fn run(self) -> Result<(), Error>

Open the window and run until it closes.

Auto Trait Implementations§

§

impl<D> !RefUnwindSafe for App<D>

§

impl<D> !Send for App<D>

§

impl<D> !Sync for App<D>

§

impl<D> !UnwindSafe for App<D>

§

impl<D> Freeze for App<D>
where Option<Format<D>>: Freeze, Vec<CommandSpec<Session<D>>>: Freeze, Option<Box<dyn FnMut(&mut Ui, &mut Cx<'_, D>)>>: Freeze,

§

impl<D> Unpin for App<D>
where Option<Format<D>>: Unpin, Vec<CommandSpec<Session<D>>>: Unpin, Option<Box<dyn FnMut(&mut Ui, &mut Cx<'_, D>)>>: Unpin,

§

impl<D> UnsafeUnpin for App<D>
where Option<Format<D>>: UnsafeUnpin, Vec<CommandSpec<Session<D>>>: UnsafeUnpin, Option<Box<dyn FnMut(&mut Ui, &mut Cx<'_, D>)>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more