Uuid

Struct Uuid 

Source
pub struct Uuid(/* private fields */);
Expand description

A simple UUID (v4) implementation.

Rather than using the uuid crate, tycho has it’s own implementation of uuids for better handling between serde and elements.

Implementations§

Source§

impl Uuid

Source

pub fn new() -> Self

Create a new uuid (any version) using a random number

Source

pub fn v4() -> Self

Create a new v4 (typed) uuid with a random number.

Source

pub fn hex(&self) -> String

Get the hex representation of the uuid (no hyphens)

use tycho::Uuid;
let uuid = Uuid::from_numeric(62911151285467627956781226334379231326);

assert_eq!(uuid.hex(), "2f543f3c06594e9233b0c8a85c2ac85e");
Source

pub fn string(&self) -> String

Get the formated hex representation of the uuid (with hyphens)

use tycho::Uuid;
let uuid = Uuid::from_numeric(62911151285467627956781226334379231326);

assert_eq!(uuid.string(), "2f543f3c-0659-4e92-33b0-c8a85c2ac85e");
Source

pub fn numeric(&self) -> u128

Get the numerical representation of the uuid as a unsigned 128-bit number.

use tycho::Uuid;
let uuid = Uuid::from_string("2f543f3c-0659-4e92-33b0-c8a85c2ac85e").unwrap();

assert_eq!(uuid.numeric(), 62911151285467627956781226334379231326);
Source

pub fn bytes(&self) -> Vec<u8>

Get the bytes representation of a uuid.

use tycho::Uuid;
let uuid = Uuid::from_string("2f543f3c-0659-4e92-33b0-c8a85c2ac85e").unwrap();
assert_eq!(uuid.bytes(), vec![47, 84, 63, 60, 6, 89, 78, 146, 51, 176, 200, 168, 92, 42, 200, 94]);
Source

pub fn slice(&self) -> [u8; 16]

Get the slice of the bytes representation of a uuid.

use tycho::Uuid;
let uuid = Uuid::from_string("2f543f3c-0659-4e92-33b0-c8a85c2ac85e").unwrap();
assert_eq!(uuid.slice(), [47, 84, 63, 60, 6, 89, 78, 146, 51, 176, 200, 168, 92, 42, 200, 94]);
Source

pub fn nil() -> Self

Get a null (0 value) uuid.

00000000-0000-0000-0000-000000000000

Source

pub fn is_nil(&self) -> bool

Check if the uuid is nil, a value of 0.

use tycho::Uuid;

let uuid = Uuid::nil();
assert_eq!(uuid.is_nil(), true);
Source

pub fn version(&self) -> u8

Get the version number of a uuid as an u8.

use tycho::Uuid;
let uuid = Uuid::from_numeric(62911151285467627956781226334379231326);

assert_eq!(uuid.version(), 4);
Source

pub fn from_numeric(x: u128) -> Self

Create an uuid from a numerical value.

use tycho::Uuid;
let uuid = Uuid::from_numeric(62911151285467627956781226334379231326);

assert_eq!(uuid.hex(), "2f543f3c06594e9233b0c8a85c2ac85e");
Source

pub fn from_hex(x: &str) -> Option<Self>

Create a uuid from an unformatted 32 length hex string.

Returns none on failure.

use tycho::Uuid;
let uuid = Uuid::from_hex("2f543f3c06594e9233b0c8a85c2ac85e").unwrap();

assert_eq!(uuid.hex(), "2f543f3c06594e9233b0c8a85c2ac85e");
Source

pub fn from_string(x: &str) -> Option<Self>

Create a uuid from an formatted 32 length hex string.

Returns none on failure.

use tycho::Uuid;
let uuid = Uuid::from_string("2f543f3c-0659-4e92-33b0-c8a85c2ac85e").unwrap();
assert_eq!(uuid.hex(), "2f543f3c06594e9233b0c8a85c2ac85e");
Source

pub fn from_string_lossy(x: &str) -> Self

Try to create a uuid from any string.

This function strips all non-hex characters and trims length of string.

If it fails, it returns a nil uuid.

use tycho::Uuid;
let uuid = Uuid::from_string_lossy("2<f54>??z3f3c-0659-[4]e92_33b0-c8a85opolc2ac85e@bbc.co.uk");

assert_eq!(uuid.hex(), "2f543f3c06594e9233b0c8a85c2ac85e");
Source

pub fn from_slice(x: [u8; 16]) -> Self

Create a uuid from a slice of length 16.

use tycho::Uuid;
let uuid = Uuid::from_slice([47, 84, 63, 60, 6, 89, 78, 146, 51, 176, 200, 168, 92, 42, 200, 94]);

assert_eq!(uuid.string(), "2f543f3c-0659-4e92-33b0-c8a85c2ac85e");
Source

pub fn from_bytes(x: &[u8]) -> Self

Create a uuid from any size vec of u8.

use tycho::Uuid;
let uuid = Uuid::from_bytes(&vec![47, 84, 63, 60, 6, 89, 78, 146, 51, 176, 200, 168, 92, 42, 200, 94]);

assert_eq!(uuid.string(), "2f543f3c-0659-4e92-33b0-c8a85c2ac85e");

Trait Implementations§

Source§

impl Clone for Uuid

Source§

fn clone(&self) -> Uuid

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 Debug for Uuid

Source§

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

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

impl Default for Uuid

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Uuid

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Self, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

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

impl Display for Uuid

Source§

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

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

impl From<Uuid> for Element

Source§

fn from(value: Uuid) -> Self

Converts to this type from the input type.
Source§

impl From<Uuid> for Uuid

Source§

fn from(x: Uuid) -> Self

Converts to this type from the input type.
Source§

impl From<Uuid> for Value

Source§

fn from(value: Uuid) -> Self

Converts to this type from the input type.
Source§

impl Hash for Uuid

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 Into<Uuid> for Uuid

Source§

fn into(self) -> Uuid

Converts this type into the (usually inferred) input type.
Source§

impl Ord for Uuid

Source§

fn cmp(&self, other: &Uuid) -> 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,

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

impl PartialEq for Uuid

Source§

fn eq(&self, other: &Uuid) -> 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 PartialOrd for Uuid

Source§

fn partial_cmp(&self, other: &Uuid) -> 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Uuid

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

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

impl TryFrom<Element> for Uuid

Source§

type Error = ()

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

fn try_from(value: Element) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Uuid

Source§

type Error = ()

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl ValueType for Uuid

Source§

const IDENT: ValueIdent = ValueIdent::UUID

Source§

impl Eq for Uuid

Source§

impl StructuralPartialEq for Uuid

Auto Trait Implementations§

§

impl Freeze for Uuid

§

impl RefUnwindSafe for Uuid

§

impl Send for Uuid

§

impl Sync for Uuid

§

impl Unpin for Uuid

§

impl UnwindSafe for Uuid

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

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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,