pub trait Persistable: Serialize + DeserializeOwned {
// Required methods
fn new(key: String) -> Self;
fn save<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn save_to_one<'life0, 'life1, 'async_trait>(
&'life0 self,
profile_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn load<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where Self: Sized + 'async_trait,
'life0: 'async_trait;
fn get_key(&self) -> String;
// Provided methods
fn load_config<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(HashMap<String, (Operator, u128)>, Operator)>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
fn save_to_all<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
fn save_to_profile<'life0, 'life1, 'async_trait>(
&'life0 self,
profile_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn load_from_operator<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
_op: &'life2 Operator,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where Self: Sized + Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn normalize_key(&self, key: &str) -> String { ... }
}Expand description
A trait for persisting objects
This trait is used to save and load objects to and from the fastest operator
An operator is a storage backend that implements the opendal::Operator
trait, such as a file system, a database, or a cloud storage service.
Required Methods§
Sourcefn save<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn save<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Save to all profiles
Sourcefn save_to_one<'life0, 'life1, 'async_trait>(
&'life0 self,
profile_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn save_to_one<'life0, 'life1, 'async_trait>(
&'life0 self,
profile_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Save to a single profile
Sourcefn load<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: Sized + 'async_trait,
'life0: 'async_trait,
fn load<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: Sized + 'async_trait,
'life0: 'async_trait,
Load a key from the fastest operator
fn get_key(&self) -> String
Provided Methods§
Sourcefn load_config<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(HashMap<String, (Operator, u128)>, Operator)>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn load_config<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(HashMap<String, (Operator, u128)>, Operator)>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
Load the configuration
Sourcefn save_to_all<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn save_to_all<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
Save to all profiles
Sourcefn save_to_profile<'life0, 'life1, 'async_trait>(
&'life0 self,
profile_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn save_to_profile<'life0, 'life1, 'async_trait>(
&'life0 self,
profile_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Save to a single profile
Sourcefn load_from_operator<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
_op: &'life2 Operator,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
fn load_from_operator<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, _op: &'life2 Operator, ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
Load from operators with fallback mechanism and cache warm-up
This function tries to load the object from storage backends in speed order. If the fastest operator fails, it will try the next fastest, and so on. When data is successfully loaded from a fallback (slower) operator, it is asynchronously written to the fastest operator for future access.
§Cache Write-back Behavior
- Non-blocking: Uses tokio::spawn for fire-and-forget
- Best-effort: Failures logged at debug level, don’t affect load
- Compressed: Objects over 1MB are compressed with zstd
- Schema evolution: If cached data fails to deserialize, cache is cleared and refetched
fn normalize_key(&self, key: &str) -> String
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl Persistable for Document
Provide Persistable implementation for Terraphim Document.
impl Persistable for Document
Provide Persistable implementation for Terraphim Document.
Each document is stored as a single JSON file across all configured
opendal profiles. The filename is derived from the id field and
normalised to be a safe filesystem key: document_<id>.json.
This allows us to persist individual articles that the user edits in the desktop UI and reload them later on any device/profile.
Source§fn new(key: String) -> Self
fn new(key: String) -> Self
Create a new, empty document instance using the provided key as the
id. All other fields are initialised with their default values.
Source§fn save_to_one<'life0, 'life1, 'async_trait>(
&'life0 self,
profile_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn save_to_one<'life0, 'life1, 'async_trait>(
&'life0 self,
profile_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Save to a single profile.
Source§fn save<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn save<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Save to all profiles.
Source§impl Persistable for Thesaurus
impl Persistable for Thesaurus
Source§fn save_to_one<'life0, 'life1, 'async_trait>(
&'life0 self,
profile_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn save_to_one<'life0, 'life1, 'async_trait>(
&'life0 self,
profile_name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Save to a single profile
Source§fn load<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn load<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Load key from the fastest operator