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§
Sourcefn backend_label(&self) -> String
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").
Sourcefn list(&self) -> Vec<String>
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.
Sourcefn read(&self, name: &str) -> Option<String>
fn read(&self, name: &str) -> Option<String>
Read a stored document by name, or None if absent/unreadable.
Provided Methods§
Sourcefn supports_file_interchange(&self) -> bool
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.
Sourcefn export_file(
&self,
name: &str,
contents: &str,
) -> Result<Option<String>, String>
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.
Sourcefn begin_import(&self) -> Result<(), String>
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.
Sourcefn take_import(&self) -> Option<(String, String)>
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.
Sourcefn begin_import_filtered(&self, _filter: (&str, &[&str])) -> Result<(), String>
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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".