PersistentState

Trait PersistentState 

Source
pub trait PersistentState<T>: Sized {
    // Required methods
    fn recover(path: &str) -> Option<Self>;
    fn update(&self, target: &T);
    fn persist(&self, path: &str) -> JoinHandle<bool>;
}
Expand description

This is a minimal design pattern crate exposing the following:

Typestate pattern: Transition trait. Java-style OO inheritance: Inherit trait. Modula-style late-binding/message-passing/signal-slot: Traits React and Message; types Callbacks<.> and ValuedCallbacks<.>, which are containers for slots.

The crate uses only abstractions from the standard library and brings no transitive dependencies.

Its main motivation was centralizing a set of traits that I kept re-inventing in my crates. As such, the crate provides minimal functionality, it just expose maximally generic types and traits useful for GUI code, to improve the software engineering side of things. Hopefully the examples are enough to represent how they might be useful for GUI code. I use the crate extensively to organize applications written in GTK, but the abstractions should be agnostic to GUI framework.

Required Methods§

Source

fn recover(path: &str) -> Option<Self>

Attempts to open UserState by deserializing it from a JSON path. This is a blocking operation.

Source

fn update(&self, target: &T)

Source

fn persist(&self, path: &str) -> JoinHandle<bool>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§