Skip to main content

ModelStore

Trait ModelStore 

Source
pub trait ModelStore {
    // Required methods
    fn backend_label(&self) -> String;
    fn list(&self) -> Vec<String>;
    fn read(&self, name: &str) -> Option<String>;
    fn write(&self, name: &str, contents: &str) -> Result<(), String>;
    fn remove(&self, name: &str) -> Result<(), String>;

    // Provided methods
    fn supports_file_interchange(&self) -> bool { ... }
    fn export_file(
        &self,
        name: &str,
        contents: &str,
    ) -> Result<Option<String>, String> { ... }
    fn begin_import(&self) -> Result<(), String> { ... }
    fn take_import(&self) -> Option<(String, String)> { ... }
    fn begin_import_filtered(
        &self,
        _filter: (&str, &[&str]),
    ) -> Result<(), String> { ... }
    fn export_file_named(
        &self,
        _file_name: &str,
        _contents: &str,
    ) -> Result<(), String> { ... }
}
Expand description

A store of NAMED model documents — the model-file half of the storage seam (distinct from the settings key/value Store). All methods take &self (any per-backend mutable state — the browser’s upload stash — lives behind interior mutability) so the app can hold one Box<dyn ModelStore> and hand panels a shared &dyn ModelStore, exactly like Store.

Required Methods§

Source

fn backend_label(&self) -> String

A short human label of where documents persist, for the panel header (e.g. "filesystem: ~/.config/brep-app/models" or "browser storage").

Source

fn list(&self) -> Vec<String>

The names of the documents currently available to Open (bare names, no extension). May be empty on a backend that cannot enumerate — then the panel falls back to the name field / import.

Source

fn read(&self, name: &str) -> Option<String>

Read a stored document by name, or None if absent/unreadable.

Source

fn write(&self, name: &str, contents: &str) -> Result<(), String>

Create or overwrite the document name with contents. Err carries a message the panel surfaces in its status line.

Source

fn remove(&self, name: &str) -> Result<(), String>

Delete the document name (best-effort; Ok if it is already gone).

Provided Methods§

Source

fn supports_file_interchange(&self) -> bool

Whether this backend can exchange files with the user’s real filesystem (browser download+upload, or a native file dialog). The panel shows the Download / Import affordances only when this is true.

Source

fn export_file( &self, name: &str, contents: &str, ) -> Result<Option<String>, String>

Hand contents to the user as a file named after name (browser: a download; native w/ dialog: a Save-As). Returns the saved document’s identity — the full path the user chose on native (so the caller can re-save straight to it), the bare download name on the web — or None when the user cancelled. No-op (None) by default.

Source

fn begin_import(&self) -> Result<(), String>

Begin importing a real file — opens the platform picker. The result is retrieved later via Self::take_import (upload/read is async in the browser). No-op by default.

Source

fn take_import(&self) -> Option<(String, String)>

Poll for a completed import as (suggested_name, contents), consuming it. None until a begin_import finishes. Default: never any.

Source

fn begin_import_filtered(&self, _filter: (&str, &[&str])) -> Result<(), String>

Begin importing a real file behind a specific picker filter (a human label + dot-less extensions, e.g. ("STEP", &["step","stp"])). The chosen file’s contents + its FULL name (extension preserved, so the panel can route it) arrive via Self::take_import. Default: reuse Self::begin_import.

Source

fn export_file_named( &self, _file_name: &str, _contents: &str, ) -> Result<(), String>

Hand contents to the user under EXACTLY file_name (extension included, no model-extension munging) — the Save-As / download for a foreign export format. Default no-op (interchange unsupported).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§