pub trait StructsyTx: Sytx + Sized {
// Required methods
fn commit(self) -> SRes<()>;
fn prepare_commit(self) -> SRes<Prepared>;
// Provided methods
fn insert<T: Persistent>(&mut self, sct: &T) -> SRes<Ref<T>> { ... }
fn update<T: Persistent>(&mut self, sref: &Ref<T>, sct: &T) -> SRes<()> { ... }
fn delete<T: Persistent>(&mut self, sref: &Ref<T>) -> SRes<()> { ... }
fn read<T: Persistent>(&mut self, sref: &Ref<T>) -> SRes<Option<T>> { ... }
fn scan<T: Persistent>(&mut self) -> SRes<TxRecordIter<'_, T>> { ... }
}
Expand description
Transaction behaviour trait.
Required Methods§
Sourcefn commit(self) -> SRes<()>
fn commit(self) -> SRes<()>
Commit a transaction
§Example
use structsy::{Structsy,StructsyTx};
let stry = Structsy::open("path/to/file.stry")?;
//....
let mut tx = stry.begin()?;
// ... operate on tx.
tx.commit()?;
Sourcefn prepare_commit(self) -> SRes<Prepared>
fn prepare_commit(self) -> SRes<Prepared>
Prepare Commit a transaction
§Example
use structsy::{Structsy,StructsyTx};
let stry = Structsy::open("path/to/file.stry")?;
//....
let mut tx = stry.begin()?;
// ... operate on tx.
let prepared = tx.prepare_commit()?;
prepared.commit()?;
Provided Methods§
Sourcefn insert<T: Persistent>(&mut self, sct: &T) -> SRes<Ref<T>>
fn insert<T: Persistent>(&mut self, sct: &T) -> SRes<Ref<T>>
Persist a new struct instance.
§Example
use structsy::{Structsy,StructsyTx};
use structsy_derive::Persistent;
#[derive(Persistent)]
struct Example {
value:u8,
}
//.. open structsy etc.
let mut tx = structsy.begin()?;
tx.insert(&Example{value:10})?;
tx.commit()?;
Sourcefn update<T: Persistent>(&mut self, sref: &Ref<T>, sct: &T) -> SRes<()>
fn update<T: Persistent>(&mut self, sref: &Ref<T>, sct: &T) -> SRes<()>
Update a persistent instance with a new value.
§Example
use structsy::{Structsy,StructsyTx};
use structsy_derive::Persistent;
#[derive(Persistent)]
struct Example {
value:u8,
}
//.. open structsy etc.
let mut tx = structsy.begin()?;
let id = tx.insert(&Example{value:10})?;
tx.update(&id, &Example{value:20})?;
tx.commit()?;
Sourcefn delete<T: Persistent>(&mut self, sref: &Ref<T>) -> SRes<()>
fn delete<T: Persistent>(&mut self, sref: &Ref<T>) -> SRes<()>
Delete a persistent instance.
§Example
use structsy::{Structsy,StructsyTx};
use structsy_derive::Persistent;
#[derive(Persistent)]
struct Example {
value:u8,
}
//.. open structsy etc.
let mut tx = structsy.begin()?;
let id = tx.insert(&Example{value:10})?;
tx.delete(&id)?;
tx.commit()?;
Sourcefn read<T: Persistent>(&mut self, sref: &Ref<T>) -> SRes<Option<T>>
fn read<T: Persistent>(&mut self, sref: &Ref<T>) -> SRes<Option<T>>
Read a persistent instance considering changes in transaction.
§Example
use structsy::{Structsy,StructsyTx};
use structsy_derive::Persistent;
#[derive(Persistent)]
struct Example {
value:u8,
}
//.. open structsy etc.
let mut tx = structsy.begin()?;
let id = tx.insert(&Example{value:10})?;
let read = tx.read(&id)?;
assert_eq!(10,read.unwrap().value);
tx.commit()?;
Sourcefn scan<T: Persistent>(&mut self) -> SRes<TxRecordIter<'_, T>>
fn scan<T: Persistent>(&mut self) -> SRes<TxRecordIter<'_, T>>
Scan persistent instances of a struct considering changes in transaction.
§Example
use structsy::{Structsy,StructsyTx};
use structsy_derive::Persistent;
#[derive(Persistent)]
struct Example {
value:u8,
}
//.. open structsy etc.
let mut tx = structsy.begin()?;
for (id, inst) in tx.scan::<Example>()? {
// logic
}
tx.commit()?;
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.