automerge/automerge/src/transaction/commit.rs
Andrew Jeffery d00cee1637 Misc API updates
- Commit now returns just a single hash rather than a vec. Since the
  change we create from committing has all of the heads as deps there
  can only be one hash/head after committing.
- Apply changes now takes a Vec rather than a slice. This avoids having
  to clone them inside.
- transact_with now passes the result of the closure to the commit
  options function
- Remove patch struct
- Change receive_sync_message to return a () instead of the
  `Option<Patch>`
- Change `Transaction*` structs to just `*` and use the transaction
  module
- Make CommitOptions fields public
2022-03-09 12:33:20 +00:00

32 lines
827 B
Rust

/// Optional metadata for a commit.
#[derive(Debug, Default, Clone)]
pub struct CommitOptions {
pub message: Option<String>,
pub time: Option<i64>,
}
impl CommitOptions {
/// Add a message to the commit.
pub fn with_message<S: Into<String>>(mut self, message: S) -> Self {
self.message = Some(message.into());
self
}
/// Add a message to the commit.
pub fn set_message<S: Into<String>>(&mut self, message: S) -> &mut Self {
self.message = Some(message.into());
self
}
/// Add a timestamp to the commit.
pub fn with_time(mut self, time: i64) -> Self {
self.time = Some(time);
self
}
/// Add a timestamp to the commit.
pub fn set_time(&mut self, time: i64) -> &mut Self {
self.time = Some(time);
self
}
}