pub struct Commit<T: Clone> {
pub timestamp: Timestamp,
pub data: T,
}
Expand description
Owned snapshot of some data T
and its Timestamp
This is a Commit
of data received from the operations
like Writer::head()
and Reader::head()
, but instead
of being shared like CommitRef
, it is fully owned.
let (reader, _) = someday::new::<String>("hello".into());
// This is a ref-counted String.
let reference: CommitRef<String> = reader.head();
// This is an owned String.
let owned: Commit<String> = reference.as_ref().clone();
// This may or may not actually deallocate the String.
drop(reference);
// The String's destructor will run here.
drop(owned);
Fields§
§timestamp: Timestamp
Timestamp of this Commit
.
Starts at 0, and increments by 1 every time a commit
-like
operation is called by the Writer
.
data: T
The generic data T
.
Implementations§
source§impl<T: Clone> Commit<T>
impl<T: Clone> Commit<T>
sourcepub fn diff(&self, other: &Self) -> boolwhere
T: PartialEq<T>,
pub fn diff(&self, other: &Self) -> boolwhere
T: PartialEq<T>,
If there is a difference in self
and other
’s timestamps or data.
// Timestamp is different.
let commit_1 = Commit { timestamp: 0, data: "a" };
let commit_2 = Commit { timestamp: 1, data: "a" };
assert!(commit_1.diff(&commit_2));
// Data is different.
let commit_3 = Commit { timestamp: 0, data: "a" };
let commit_4 = Commit { timestamp: 0, data: "b" };
assert!(commit_3.diff(&commit_4));
// Same.
let commit_5 = Commit { timestamp: 0, data: "a" };
let commit_6 = Commit { timestamp: 0, data: "a" };
assert!(!commit_5.diff(&commit_6));
sourcepub const fn diff_timestamp(&self, other: &Self) -> bool
pub const fn diff_timestamp(&self, other: &Self) -> bool
If there is a difference in self
& other
’s timestamps.
// Timestamp is different, data is same.
let commit_1 = Commit { timestamp: 0, data: "" };
let commit_2 = Commit { timestamp: 1, data: "" };
assert!(commit_1.diff_timestamp(&commit_2));
// Timestamp is same, data is different.
let commit_3 = Commit { timestamp: 0, data: "" };
let commit_4 = Commit { timestamp: 0, data: "a" };
assert!(!commit_3.diff_timestamp(&commit_4));
sourcepub fn diff_data(&self, other: &Self) -> boolwhere
T: PartialEq<T>,
pub fn diff_data(&self, other: &Self) -> boolwhere
T: PartialEq<T>,
If there is a difference in self
& other
’s timestamps.
// Timestamp is different, data is same.
let commit_1 = Commit { timestamp: 0, data: "a" };
let commit_2 = Commit { timestamp: 1, data: "a" };
assert!(!commit_1.diff_data(&commit_2));
// Timestamp is same, data is different.
let commit_3 = Commit { timestamp: 0, data: "a" };
let commit_4 = Commit { timestamp: 0, data: "b" };
assert!(commit_3.diff_data(&commit_4));
sourcepub const fn ahead(&self, other: &Self) -> bool
pub const fn ahead(&self, other: &Self) -> bool
If self
’s timestamp is ahead of other
’s timestamp.
let commit_1 = Commit { timestamp: 0, data: "" };
let commit_2 = Commit { timestamp: 1, data: "" };
assert!(!commit_1.ahead(&commit_2));
let commit_3 = Commit { timestamp: 2, data: "" };
let commit_4 = Commit { timestamp: 1, data: "" };
assert!(commit_3.ahead(&commit_4));
let commit_5 = Commit { timestamp: 2, data: "" };
let commit_6 = Commit { timestamp: 2, data: "" };
assert!(!commit_5.ahead(&commit_6));
sourcepub const fn behind(&self, other: &Self) -> bool
pub const fn behind(&self, other: &Self) -> bool
If self
’s timestamp is behind of other
’s timestamp.
let commit_1 = Commit { timestamp: 0, data: "" };
let commit_2 = Commit { timestamp: 1, data: "" };
assert!(commit_1.behind(&commit_2));
let commit_3 = Commit { timestamp: 2, data: "" };
let commit_4 = Commit { timestamp: 1, data: "" };
assert!(!commit_3.behind(&commit_4));
let commit_5 = Commit { timestamp: 2, data: "" };
let commit_6 = Commit { timestamp: 2, data: "" };
assert!(!commit_5.behind(&commit_6));
Trait Implementations§
source§impl<'__de, T> BorrowDecode<'__de> for Commit<T>where
T: BorrowDecode<'__de> + Clone,
impl<'__de, T> BorrowDecode<'__de> for Commit<T>where
T: BorrowDecode<'__de> + Clone,
source§fn borrow_decode<__D: BorrowDecoder<'__de>>(
decoder: &mut __D
) -> Result<Self, DecodeError>
fn borrow_decode<__D: BorrowDecoder<'__de>>( decoder: &mut __D ) -> Result<Self, DecodeError>
Attempt to decode this type with the given BorrowDecode.
source§impl<T> BorshDeserialize for Commit<T>where
T: BorshDeserialize + Clone,
impl<T> BorshDeserialize for Commit<T>where
T: BorshDeserialize + Clone,
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self, Error>
source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Deserializes this instance from a given slice of bytes.
Updates the buffer to point at the remaining bytes.
source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
Deserialize this instance from a slice of bytes.
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
source§impl<T> BorshSerialize for Commit<T>where
T: BorshSerialize + Clone,
impl<T> BorshSerialize for Commit<T>where
T: BorshSerialize + Clone,
source§impl<'de, T> Deserialize<'de> for Commit<T>where
T: Deserialize<'de> + Clone,
impl<'de, T> Deserialize<'de> for Commit<T>where
T: Deserialize<'de> + Clone,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<T: Ord + Clone> Ord for Commit<T>
impl<T: Ord + Clone> Ord for Commit<T>
source§impl<T: PartialEq + Clone> PartialEq for Commit<T>
impl<T: PartialEq + Clone> PartialEq for Commit<T>
source§impl<T: PartialOrd + Clone> PartialOrd for Commit<T>
impl<T: PartialOrd + Clone> PartialOrd for Commit<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl<T: Clone> TryFrom<Arc<Commit<T>>> for Commit<T>
impl<T: Clone> TryFrom<Arc<Commit<T>>> for Commit<T>
source§fn try_from(commit: CommitRef<T>) -> Result<Self, Self::Error>
fn try_from(commit: CommitRef<T>) -> Result<Self, Self::Error>
This cheaply acquires ownership of a shared CommitRef
if you are the only one holding onto it.
let (r, mut w) = someday::new(String::from("hello"));
let commit_ref = r.head();
// Force the `Writer` to advance onto the next commit.
w.add_commit_push(|_, _| {});
// Now there's only 1 strong count on `commit_ref`,
// this can be turned into an owned commit.
let commit_owned: Commit<String> = commit_ref.try_into().unwrap();
impl<T: Copy + Clone> Copy for Commit<T>
impl<T: Eq + Clone> Eq for Commit<T>
impl<T: Clone> StructuralPartialEq for Commit<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for Commit<T>where
T: RefUnwindSafe,
impl<T> Send for Commit<T>where
T: Send,
impl<T> Sync for Commit<T>where
T: Sync,
impl<T> Unpin for Commit<T>where
T: Unpin,
impl<T> UnwindSafe for Commit<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more