Struct someday::Commit

source ·
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>

source

pub fn diff(&self, other: &Self) -> bool
where 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));
source

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));
source

pub fn diff_data(&self, other: &Self) -> bool
where 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));
source

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));
source

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,

source§

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>

source§

fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self, Error>

source§

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>

Deserialize this instance from a slice of bytes.
source§

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,

source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<(), Error>

source§

impl<T: Clone + Clone> Clone for Commit<T>

source§

fn clone(&self) -> Commit<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug + Clone> Debug for Commit<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Decode for Commit<T>
where T: Decode + Clone,

source§

fn decode<__D: Decoder>(decoder: &mut __D) -> Result<Self, DecodeError>

Attempt to decode this type with the given Decode.
source§

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>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T> Display for Commit<T>
where T: Clone + Display,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

let (r, mut w) = someday::new(String::from("hello"));

let display: String = format!("{}", r.head());
assert_eq!(display, "hello");
source§

impl<T> Encode for Commit<T>
where T: Encode + Clone,

source§

fn encode<__E: Encoder>(&self, encoder: &mut __E) -> Result<(), EncodeError>

Encode a given type.
source§

impl<T: Clone> From<Commit<T>> for Writer<T>

source§

fn from(commit: Commit<T>) -> Self

Same as crate::free::from_commit but without creating a Reader.

source§

impl<T: Hash + Clone> Hash for Commit<T>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: Ord + Clone> Ord for Commit<T>

source§

fn cmp(&self, other: &Commit<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<T: PartialEq + Clone> PartialEq for Commit<T>

source§

fn eq(&self, other: &Commit<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialOrd + Clone> PartialOrd for Commit<T>

source§

fn partial_cmp(&self, other: &Commit<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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 more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T> Serialize for Commit<T>
where T: Serialize + Clone,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: Clone> TryFrom<Arc<Commit<T>>> for Commit<T>

source§

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();
§

type Error = Arc<Commit<T>>

The type returned in the event of a conversion error.
source§

impl<T: Copy + Clone> Copy for Commit<T>

source§

impl<T: Eq + Clone> Eq for Commit<T>

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,