Transactions with no ops in them are generally undesirable. They take up space in the change log but do nothing else. They are not useless though, it may occasionally be necessary to create an empty change in order to list all the current heads of the document as dependents of the empty change. The current API makes no distinction between empty changes and non-empty changes. If the user calls `Transaction::commit` a change is created regardless of whether there are ops to commit. To provide a more useful API modify `commit` so that if there is a no-op transaction then no changes are created, but provide explicit methods to create an empty change via `Transaction::empty_change`, `Automerge::empty_change` and `Autocommit::empty_change`. Also make these APIs available in Javascript and C.
20 lines
585 B
Rust
20 lines
585 B
Rust
use crate::ChangeHash;
|
|
|
|
/// The result of a successful, and committed, transaction.
|
|
#[derive(Debug)]
|
|
pub struct Success<O, Obs> {
|
|
/// The result of the transaction.
|
|
pub result: O,
|
|
/// The hash of the change, will be `None` if the transaction did not create any operations
|
|
pub hash: Option<ChangeHash>,
|
|
pub op_observer: Obs,
|
|
}
|
|
|
|
/// The result of a failed, and rolled back, transaction.
|
|
#[derive(Debug)]
|
|
pub struct Failure<E> {
|
|
/// The error returned from the transaction.
|
|
pub error: E,
|
|
/// The number of operations cancelled.
|
|
pub cancelled: usize,
|
|
}
|