Struct Oid

Source
pub struct Oid<P> { /* private fields */ }
Expand description

A Typed Object ID where the Prefix is part of the type

§Examples

A nice property of this two different prefix are two different types, and thus the following fails to compile:

struct A;
impl OidPrefix for A {}

struct B;
impl OidPrefix for B {}

// The same UUID for both
let oid_a: Oid<A> = Oid::try_with_uuid("b3cfdafa-3fec-41e2-82bf-ff881131abf1").unwrap();
let oid_b: Oid<B> = Oid::try_with_uuid("b3cfdafa-3fec-41e2-82bf-ff881131abf1").unwrap();

// This fails to compile because `Oid<A>` is a different type than `Oid<B>` and no
// PartialEq or Eq is implemented between these two types.
oid_a == oid_b

Implementations§

Source§

impl<P: OidPrefix> Oid<P>

Source

pub fn new_v4() -> Self

Available on crate feature uuid_v4 only.

Create a new Oid with a UUIDv4 (random)

Source

pub fn new_v7_now() -> Self

Available on crate feature uuid_v7 only.

Create a new Oid with a UUIDv7 (UNIX Epoch based for current system clock)

Source

pub fn new_v7(ts: Timestamp) -> Self

Available on crate feature uuid_v7 only.

Create a new Oid with a UUIDv7 (UNIX Epoch based)

Source

pub fn with_uuid(uuid: Uuid) -> Self

Create a new Oid with a given UUID

Source

pub fn try_with_uuid<S: AsRef<str>>(uuid: S) -> Result<Self>

Attempts to create a new Oid with a given string-ish UUID

Source

pub fn try_with_uuid_base32<S: AsRef<str>>(base32_uuid: S) -> Result<Self>

Attemp to create an Oid from a base32hex encoded UUID string-ish value

Source

pub fn prefix(&self) -> Prefix

Get the Prefix of the TOID

§Panics

If the Type P translates to an invalid prefix

Source

pub fn value(&self) -> String

Get the value portion of the of the TOID, which is the base32 encoded string following the - separator

Source

pub fn uuid(&self) -> &Uuid

Get the UUID of the TOID

Trait Implementations§

Source§

impl<P> Clone for Oid<P>

Source§

fn clone(&self) -> Self

Returns a duplicate 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<P> Debug for Oid<P>

Source§

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

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

impl<'de, P: OidPrefix> Deserialize<'de> for Oid<P>

Available on crate feature serde only.
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<P: OidPrefix> Display for Oid<P>

Source§

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

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

impl<P: OidPrefix> FromStr for Oid<P>

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<P> Hash for Oid<P>
where P: OidPrefix,

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<P: PartialEq> PartialEq for Oid<P>

Source§

fn eq(&self, other: &Oid<P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P: OidPrefix> Serialize for Oid<P>

Available on crate feature serde only.
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<P: OidPrefix> TryFrom<Thing> for Oid<P>

Available on crate feature surrealdb only.
Source§

type Error = Error

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

fn try_from(thing: Thing) -> Result<Self>

Performs the conversion.
Source§

impl<P> Copy for Oid<P>

Source§

impl<P: Eq> Eq for Oid<P>

Source§

impl<P> StructuralPartialEq for Oid<P>

Auto Trait Implementations§

§

impl<P> Freeze for Oid<P>

§

impl<P> RefUnwindSafe for Oid<P>

§

impl<P> Send for Oid<P>

§

impl<P> Sync for Oid<P>

§

impl<P> Unpin for Oid<P>

§

impl<P> UnwindSafe for Oid<P>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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> ToSmolStr for T
where T: Display + ?Sized,

Source§

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

Source§

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

Source§

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

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool

Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool

Source§

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

Source§

impl<T> ErasedDestructor for T
where T: 'static,