rocket::serde::uuid

Struct Uuid

Source
pub struct Uuid(/* private fields */);
Available on crate feature uuid only.
Expand description

A Universally Unique Identifier (UUID).

§Examples

Parse a UUID given in the simple format and print it as a urn:

let my_uuid = Uuid::parse_str("a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8")?;

println!("{}", my_uuid.urn());

Create a new random (V4) UUID and print it out in hexadecimal form:

// Note that this requires the `v4` feature enabled in the uuid crate.
let my_uuid = Uuid::new_v4();

println!("{}", my_uuid);

§Formatting

A UUID can be formatted in one of a few ways:

  • simple: a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8.
  • hyphenated: a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8.
  • urn: urn:uuid:A1A2A3A4-B1B2-C1C2-D1D2-D3D4D5D6D7D8.
  • braced: {a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8}.

The default representation when formatting a UUID with Display is hyphenated:

let my_uuid = Uuid::parse_str("a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8")?;

assert_eq!(
    "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8",
    my_uuid.to_string(),
);

Other formats can be specified using adapter methods on the UUID:

let my_uuid = Uuid::parse_str("a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8")?;

assert_eq!(
    "urn:uuid:a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8",
    my_uuid.urn().to_string(),
);

§Endianness

The specification for UUIDs encodes the integer fields that make up the value in big-endian order. This crate assumes integer inputs are already in the correct order by default, regardless of the endianness of the environment. Most methods that accept integers have a _le variant (such as from_fields_le) that assumes any integer values will need to have their bytes flipped, regardless of the endianness of the environment.

Most users won’t need to worry about endianness unless they need to operate on individual fields (such as when converting between Microsoft GUIDs). The important things to remember are:

  • The endianness is in terms of the fields of the UUID, not the environment.
  • The endianness is assumed to be big-endian when there’s no _le suffix somewhere.
  • Byte-flipping in _le methods applies to each integer.
  • Endianness roundtrips, so if you create a UUID with from_fields_le you’ll get the same values back out with to_fields_le.

§ABI

The Uuid type is always guaranteed to be have the same ABI as Bytes.

Implementations§

Source§

impl Uuid

Source

pub const fn nil() -> Uuid

The ‘nil UUID’ (all zeros).

The nil UUID is a special form of UUID that is specified to have all 128 bits set to zero.

§References
§Examples

Basic usage:

let uuid = Uuid::nil();

assert_eq!(
    "00000000-0000-0000-0000-000000000000",
    uuid.hyphenated().to_string(),
);
Source

pub const fn max() -> Uuid

The ‘max UUID’ (all ones).

The max UUID is a special form of UUID that is specified to have all 128 bits set to one.

§References
§Examples

Basic usage:

let uuid = Uuid::max();

assert_eq!(
    "ffffffff-ffff-ffff-ffff-ffffffffffff",
    uuid.hyphenated().to_string(),
);
Source

pub const fn from_fields(d1: u32, d2: u16, d3: u16, d4: &[u8; 8]) -> Uuid

Creates a UUID from four field values.

§Examples

Basic usage:

let d1 = 0xa1a2a3a4;
let d2 = 0xb1b2;
let d3 = 0xc1c2;
let d4 = [0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8];

let uuid = Uuid::from_fields(d1, d2, d3, &d4);

assert_eq!(
    "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8",
    uuid.hyphenated().to_string(),
);
Source

pub const fn from_fields_le(d1: u32, d2: u16, d3: u16, d4: &[u8; 8]) -> Uuid

Creates a UUID from four field values in little-endian order.

The bytes in the d1, d2 and d3 fields will be flipped to convert into big-endian order. This is based on the endianness of the UUID, rather than the target environment so bytes will be flipped on both big and little endian machines.

§Examples

Basic usage:

let d1 = 0xa1a2a3a4;
let d2 = 0xb1b2;
let d3 = 0xc1c2;
let d4 = [0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8];

let uuid = Uuid::from_fields_le(d1, d2, d3, &d4);

assert_eq!(
    "a4a3a2a1-b2b1-c2c1-d1d2-d3d4d5d6d7d8",
    uuid.hyphenated().to_string(),
);
Source

pub const fn from_u128(v: u128) -> Uuid

Creates a UUID from a 128bit value.

§Examples

Basic usage:

let v = 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8u128;

let uuid = Uuid::from_u128(v);

assert_eq!(
    "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8",
    uuid.hyphenated().to_string(),
);
Source

pub const fn from_u128_le(v: u128) -> Uuid

Creates a UUID from a 128bit value in little-endian order.

The entire value will be flipped to convert into big-endian order. This is based on the endianness of the UUID, rather than the target environment so bytes will be flipped on both big and little endian machines.

§Examples

Basic usage:

let v = 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8u128;

let uuid = Uuid::from_u128_le(v);

assert_eq!(
    "d8d7d6d5-d4d3-d2d1-c2c1-b2b1a4a3a2a1",
    uuid.hyphenated().to_string(),
);
Source

pub const fn from_u64_pair(high_bits: u64, low_bits: u64) -> Uuid

Creates a UUID from two 64bit values.

§Examples

Basic usage:

let hi = 0xa1a2a3a4b1b2c1c2u64;
let lo = 0xd1d2d3d4d5d6d7d8u64;

let uuid = Uuid::from_u64_pair(hi, lo);

assert_eq!(
    "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8",
    uuid.hyphenated().to_string(),
);
Source

pub fn from_slice(b: &[u8]) -> Result<Uuid, Error>

Creates a UUID using the supplied bytes.

§Errors

This function will return an error if b has any length other than 16.

§Examples

Basic usage:

let bytes = [
    0xa1, 0xa2, 0xa3, 0xa4,
    0xb1, 0xb2,
    0xc1, 0xc2,
    0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
];

let uuid = Uuid::from_slice(&bytes)?;

assert_eq!(
    "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8",
    uuid.hyphenated().to_string(),
);
Source

pub fn from_slice_le(b: &[u8]) -> Result<Uuid, Error>

Creates a UUID using the supplied bytes in little endian order.

The individual fields encoded in the buffer will be flipped.

§Errors

This function will return an error if b has any length other than 16.

§Examples

Basic usage:

let bytes = [
    0xa1, 0xa2, 0xa3, 0xa4,
    0xb1, 0xb2,
    0xc1, 0xc2,
    0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
];

let uuid = Uuid::from_slice_le(&bytes)?;

assert_eq!(
    uuid.hyphenated().to_string(),
    "a4a3a2a1-b2b1-c2c1-d1d2-d3d4d5d6d7d8"
);
Source

pub const fn from_bytes(bytes: [u8; 16]) -> Uuid

Creates a UUID using the supplied bytes.

§Examples

Basic usage:

let bytes = [
    0xa1, 0xa2, 0xa3, 0xa4,
    0xb1, 0xb2,
    0xc1, 0xc2,
    0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
];

let uuid = Uuid::from_bytes(bytes);

assert_eq!(
    uuid.hyphenated().to_string(),
    "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8"
);
Source

pub const fn from_bytes_le(b: [u8; 16]) -> Uuid

Creates a UUID using the supplied bytes in little endian order.

The individual fields encoded in the buffer will be flipped.

§Examples

Basic usage:

let bytes = [
    0xa1, 0xa2, 0xa3, 0xa4,
    0xb1, 0xb2,
    0xc1, 0xc2,
    0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
];

let uuid = Uuid::from_bytes_le(bytes);

assert_eq!(
    "a4a3a2a1-b2b1-c2c1-d1d2-d3d4d5d6d7d8",
    uuid.hyphenated().to_string(),
);
Source

pub fn from_bytes_ref(bytes: &[u8; 16]) -> &Uuid

Creates a reference to a UUID from a reference to the supplied bytes.

§Examples

Basic usage:

let bytes = [
    0xa1, 0xa2, 0xa3, 0xa4,
    0xb1, 0xb2,
    0xc1, 0xc2,
    0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
];

let uuid = Uuid::from_bytes_ref(&bytes);

assert_eq!(
    uuid.hyphenated().to_string(),
    "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8"
);

assert!(std::ptr::eq(
    uuid as *const Uuid as *const u8,
    &bytes as *const [u8; 16] as *const u8,
));
Source§

impl Uuid

Source

pub fn parse_str(input: &str) -> Result<Uuid, Error>

Parses a Uuid from a string of hexadecimal digits with optional hyphens.

Any of the formats generated by this module (simple, hyphenated, urn, Microsoft GUID) are supported by this parsing function.

Prefer try_parse unless you need detailed user-facing diagnostics. This method will be eventually deprecated in favor of try_parse.

§Examples

Parse a hyphenated UUID:

let uuid = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000")?;

assert_eq!(Some(Version::Random), uuid.get_version());
assert_eq!(Variant::RFC4122, uuid.get_variant());
Source

pub const fn try_parse(input: &str) -> Result<Uuid, Error>

Parses a Uuid from a string of hexadecimal digits with optional hyphens.

This function is similar to parse_str, in fact parse_str shares the same underlying parser. The difference is that if try_parse fails, it won’t generate very useful error messages. The parse_str function will eventually be deprecated in favor of try_parse.

To parse a UUID from a byte stream instead of a UTF8 string, see try_parse_ascii.

§Examples

Parse a hyphenated UUID:

let uuid = Uuid::try_parse("550e8400-e29b-41d4-a716-446655440000")?;

assert_eq!(Some(Version::Random), uuid.get_version());
assert_eq!(Variant::RFC4122, uuid.get_variant());
Source

pub const fn try_parse_ascii(input: &[u8]) -> Result<Uuid, Error>

Parses a Uuid from a string of hexadecimal digits with optional hyphens.

The input is expected to be a string of ASCII characters. This method can be more convenient than try_parse if the UUID is being parsed from a byte stream instead of from a UTF8 string.

§Examples

Parse a hyphenated UUID:

let uuid = Uuid::try_parse_ascii(b"550e8400-e29b-41d4-a716-446655440000")?;

assert_eq!(Some(Version::Random), uuid.get_version());
assert_eq!(Variant::RFC4122, uuid.get_variant());
Source§

impl Uuid

Source

pub const fn hyphenated(self) -> Hyphenated

Get a Hyphenated formatter.

Source

pub fn as_hyphenated(&self) -> &Hyphenated

Get a borrowed Hyphenated formatter.

Source

pub const fn simple(self) -> Simple

Get a Simple formatter.

Source

pub fn as_simple(&self) -> &Simple

Get a borrowed Simple formatter.

Source

pub const fn urn(self) -> Urn

Get a Urn formatter.

Source

pub fn as_urn(&self) -> &Urn

Get a borrowed Urn formatter.

Source

pub const fn braced(self) -> Braced

Get a Braced formatter.

Source

pub fn as_braced(&self) -> &Braced

Get a borrowed Braced formatter.

Source§

impl Uuid

Source

pub fn new_v4() -> Uuid

Creates a random UUID.

This uses the getrandom crate to utilise the operating system’s RNG as the source of random numbers. If you’d like to use a custom generator, don’t use this method: generate random bytes using your custom generator and pass them to the uuid::Builder::from_random_bytes function instead.

Note that usage of this method requires the v4 feature of this crate to be enabled.

§Examples

Basic usage:

let uuid = Uuid::new_v4();

assert_eq!(Some(Version::Random), uuid.get_version());
§References
Source§

impl Uuid

Source

pub const NAMESPACE_DNS: Uuid = _

UUID namespace for Domain Name System (DNS).

Source

pub const NAMESPACE_OID: Uuid = _

UUID namespace for ISO Object Identifiers (OIDs).

Source

pub const NAMESPACE_URL: Uuid = _

UUID namespace for Uniform Resource Locators (URLs).

Source

pub const NAMESPACE_X500: Uuid = _

UUID namespace for X.500 Distinguished Names (DNs).

Source

pub const fn get_variant(&self) -> Variant

Returns the variant of the UUID structure.

This determines the interpretation of the structure of the UUID. This method simply reads the value of the variant byte. It doesn’t validate the rest of the UUID as conforming to that variant.

§Examples

Basic usage:

let my_uuid = Uuid::parse_str("02f09a3f-1624-3b1d-8409-44eff7708208")?;

assert_eq!(Variant::RFC4122, my_uuid.get_variant());
§References
Source

pub const fn get_version_num(&self) -> usize

Returns the version number of the UUID.

This represents the algorithm used to generate the value. This method is the future-proof alternative to Uuid::get_version.

§Examples

Basic usage:

let my_uuid = Uuid::parse_str("02f09a3f-1624-3b1d-8409-44eff7708208")?;

assert_eq!(3, my_uuid.get_version_num());
§References
Source

pub const fn get_version(&self) -> Option<Version>

Returns the version of the UUID.

This represents the algorithm used to generate the value. If the version field doesn’t contain a recognized version then None is returned. If you’re trying to read the version for a future extension you can also use Uuid::get_version_num to unconditionally return a number. Future extensions may start to return Some once they’re standardized and supported.

§Examples

Basic usage:

let my_uuid = Uuid::parse_str("02f09a3f-1624-3b1d-8409-44eff7708208")?;

assert_eq!(Some(Version::Md5), my_uuid.get_version());
§References
Source

pub fn as_fields(&self) -> (u32, u16, u16, &[u8; 8])

Returns the four field values of the UUID.

These values can be passed to the Uuid::from_fields method to get the original Uuid back.

  • The first field value represents the first group of (eight) hex digits, taken as a big-endian u32 value. For V1 UUIDs, this field represents the low 32 bits of the timestamp.
  • The second field value represents the second group of (four) hex digits, taken as a big-endian u16 value. For V1 UUIDs, this field represents the middle 16 bits of the timestamp.
  • The third field value represents the third group of (four) hex digits, taken as a big-endian u16 value. The 4 most significant bits give the UUID version, and for V1 UUIDs, the last 12 bits represent the high 12 bits of the timestamp.
  • The last field value represents the last two groups of four and twelve hex digits, taken in order. The first 1-3 bits of this indicate the UUID variant, and for V1 UUIDs, the next 13-15 bits indicate the clock sequence and the last 48 bits indicate the node ID.
§Examples
let uuid = Uuid::nil();

assert_eq!(uuid.as_fields(), (0, 0, 0, &[0u8; 8]));

let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?;

assert_eq!(
    uuid.as_fields(),
    (
        0xa1a2a3a4,
        0xb1b2,
        0xc1c2,
        &[0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8],
    )
);
Source

pub fn to_fields_le(&self) -> (u32, u16, u16, &[u8; 8])

Returns the four field values of the UUID in little-endian order.

The bytes in the returned integer fields will be converted from big-endian order. This is based on the endianness of the UUID, rather than the target environment so bytes will be flipped on both big and little endian machines.

§Examples
use uuid::Uuid;

let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?;

assert_eq!(
    uuid.to_fields_le(),
    (
        0xa4a3a2a1,
        0xb2b1,
        0xc2c1,
        &[0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8],
    )
);
Source

pub const fn as_u128(&self) -> u128

Returns a 128bit value containing the value.

The bytes in the UUID will be packed directly into a u128.

§Examples
let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?;

assert_eq!(
    uuid.as_u128(),
    0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8,
);
Source

pub const fn to_u128_le(&self) -> u128

Returns a 128bit little-endian value containing the value.

The bytes in the u128 will be flipped to convert into big-endian order. This is based on the endianness of the UUID, rather than the target environment so bytes will be flipped on both big and little endian machines.

Note that this will produce a different result than Uuid::to_fields_le, because the entire UUID is reversed, rather than reversing the individual fields in-place.

§Examples
let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?;

assert_eq!(
    uuid.to_u128_le(),
    0xd8d7d6d5d4d3d2d1c2c1b2b1a4a3a2a1,
);
Source

pub const fn as_u64_pair(&self) -> (u64, u64)

Returns two 64bit values containing the value.

The bytes in the UUID will be split into two u64. The first u64 represents the 64 most significant bits, the second one represents the 64 least significant.

§Examples
let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?;
assert_eq!(
    uuid.as_u64_pair(),
    (0xa1a2a3a4b1b2c1c2, 0xd1d2d3d4d5d6d7d8),
);
Source

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

Returns a slice of 16 octets containing the value.

This method borrows the underlying byte value of the UUID.

§Examples
let bytes1 = [
    0xa1, 0xa2, 0xa3, 0xa4,
    0xb1, 0xb2,
    0xc1, 0xc2,
    0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
];
let uuid1 = Uuid::from_bytes_ref(&bytes1);

let bytes2 = uuid1.as_bytes();
let uuid2 = Uuid::from_bytes_ref(bytes2);

assert_eq!(uuid1, uuid2);

assert!(std::ptr::eq(
    uuid2 as *const Uuid as *const u8,
    &bytes1 as *const [u8; 16] as *const u8,
));
Source

pub const fn into_bytes(self) -> [u8; 16]

Consumes self and returns the underlying byte value of the UUID.

§Examples
let bytes = [
    0xa1, 0xa2, 0xa3, 0xa4,
    0xb1, 0xb2,
    0xc1, 0xc2,
    0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
];
let uuid = Uuid::from_bytes(bytes);
assert_eq!(bytes, uuid.into_bytes());
Source

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

Returns the bytes of the UUID in little-endian order.

The bytes will be flipped to convert into little-endian order. This is based on the endianness of the UUID, rather than the target environment so bytes will be flipped on both big and little endian machines.

§Examples
use uuid::Uuid;

let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?;

assert_eq!(
    uuid.to_bytes_le(),
    ([
        0xa4, 0xa3, 0xa2, 0xa1, 0xb2, 0xb1, 0xc2, 0xc1, 0xd1, 0xd2,
        0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8
    ])
);
Source

pub const fn is_nil(&self) -> bool

Tests if the UUID is nil (all zeros).

Source

pub const fn is_max(&self) -> bool

Tests if the UUID is max (all ones).

Source

pub const fn encode_buffer() -> [u8; 45]

A buffer that can be used for encode_... calls, that is guaranteed to be long enough for any of the format adapters.

§Examples
let uuid = Uuid::nil();

assert_eq!(
    uuid.simple().encode_lower(&mut Uuid::encode_buffer()),
    "00000000000000000000000000000000"
);

assert_eq!(
    uuid.hyphenated()
        .encode_lower(&mut Uuid::encode_buffer()),
    "00000000-0000-0000-0000-000000000000"
);

assert_eq!(
    uuid.urn().encode_lower(&mut Uuid::encode_buffer()),
    "urn:uuid:00000000-0000-0000-0000-000000000000"
);
Source

pub const fn get_timestamp(&self) -> Option<Timestamp>

If the UUID is the correct version (v1, v6, or v7) this will return the timestamp in a version-agnostic Timestamp. For other versions this will return None.

§Roundtripping

This method is unlikely to roundtrip a timestamp in a UUID due to the way UUIDs encode timestamps. The timestamp returned from this method will be truncated to 100ns precision for version 1 and 6 UUIDs, and to millisecond precision for version 7 UUIDs.

Source

pub const fn get_node_id(&self) -> Option<[u8; 6]>

If the UUID is the correct version (v1, or v6) this will return the node value as a 6-byte array. For other versions this will return None.

Trait Implementations§

Source§

impl AsRef<[u8]> for Uuid

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Uuid> for Braced

Source§

fn as_ref(&self) -> &Uuid

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Uuid> for Hyphenated

Source§

fn as_ref(&self) -> &Uuid

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Uuid> for Simple

Source§

fn as_ref(&self) -> &Uuid

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Uuid> for Urn

Source§

fn as_ref(&self) -> &Uuid

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Uuid> for Uuid

Source§

fn as_ref(&self) -> &Uuid

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<Uuid> for Braced

Source§

fn borrow(&self) -> &Uuid

Immutably borrows from an owned value. Read more
Source§

impl Borrow<Uuid> for Hyphenated

Source§

fn borrow(&self) -> &Uuid

Immutably borrows from an owned value. Read more
Source§

impl Borrow<Uuid> for Simple

Source§

fn borrow(&self) -> &Uuid

Immutably borrows from an owned value. Read more
Source§

impl Borrow<Uuid> for Urn

Source§

fn borrow(&self) -> &Uuid

Immutably borrows from an owned value. Read more
Source§

impl Clone for Uuid

Source§

fn clone(&self) -> Uuid

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

Source§

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

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

impl Default for Uuid

Source§

fn default() -> Uuid

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

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

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Uuid, <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<(), Error>

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

impl From<Braced> for Uuid

Source§

fn from(f: Braced) -> Uuid

Converts to this type from the input type.
Source§

impl From<Hyphenated> for Uuid

Source§

fn from(f: Hyphenated) -> Uuid

Converts to this type from the input type.
Source§

impl From<Simple> for Uuid

Source§

fn from(f: Simple) -> Uuid

Converts to this type from the input type.
Source§

impl From<Urn> for Uuid

Source§

fn from(f: Urn) -> Uuid

Converts to this type from the input type.
Source§

impl From<Uuid> for Braced

Source§

fn from(f: Uuid) -> Braced

Converts to this type from the input type.
Source§

impl From<Uuid> for Hyphenated

Source§

fn from(f: Uuid) -> Hyphenated

Converts to this type from the input type.
Source§

impl From<Uuid> for Simple

Source§

fn from(f: Uuid) -> Simple

Converts to this type from the input type.
Source§

impl From<Uuid> for String

Source§

fn from(uuid: Uuid) -> String

Converts to this type from the input type.
Source§

impl From<Uuid> for Urn

Source§

fn from(f: Uuid) -> Urn

Converts to this type from the input type.
Source§

impl From<Uuid> for Vec<u8>

Source§

fn from(value: Uuid) -> Vec<u8>

Converts to this type from the input type.
Source§

impl<'v> FromFormField<'v> for Uuid

Source§

fn from_value(field: ValueField<'v>) -> Result<'v, Self>

Parse a value of T from a form value field. Read more
Source§

fn from_data<'life0, 'async_trait>( field: DataField<'v, 'life0>, ) -> Pin<Box<dyn Future<Output = Result<'v, Self>> + Send + 'async_trait>>
where Self: 'async_trait, 'v: 'async_trait, 'life0: 'async_trait,

Parse a value of T from a form data field. Read more
Source§

fn default() -> Option<Self>

Returns a default value, if any exists, to be used during lenient parsing when the form field is missing. Read more
Source§

impl<'a> FromParam<'a> for Uuid

Source§

fn from_param(param: &'a str) -> Result<Uuid, Self::Error>

A value is successfully parsed if param is a properly formatted Uuid. Otherwise, an error is returned.

Source§

type Error = Error

The associated error to be returned if parsing/validation fails.
Source§

impl FromStr for Uuid

Source§

type Err = Error

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

fn from_str(uuid_str: &str) -> Result<Uuid, <Uuid as FromStr>::Err>

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

impl<'x, P> FromUriParam<P, &'x Uuid> for Uuid
where P: Part,

§

type Target = &'x Uuid

The resulting type of this conversion.
§

fn from_uri_param(param: &'x Uuid) -> &'x Uuid

Converts a value of type T into a value of type Self::Target. The resulting value of type Self::Target will be rendered into a URI using its UriDisplay implementation.
§

impl<'x, P> FromUriParam<P, &'x mut Uuid> for Uuid
where P: Part,

§

type Target = &'x mut Uuid

The resulting type of this conversion.
§

fn from_uri_param(param: &'x mut Uuid) -> &'x mut Uuid

Converts a value of type T into a value of type Self::Target. The resulting value of type Self::Target will be rendered into a URI using its UriDisplay implementation.
§

impl<P> FromUriParam<P, Uuid> for Uuid
where P: Part,

§

type Target = Uuid

The resulting type of this conversion.
§

fn from_uri_param(param: Uuid) -> Uuid

Converts a value of type T into a value of type Self::Target. The resulting value of type Self::Target will be rendered into a URI using its UriDisplay implementation.
Source§

impl Hash for Uuid

Source§

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

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

Source§

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

Formats the value using the given formatter. Read more
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<&str> for Uuid

Source§

type Error = Error

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

fn try_from(uuid_str: &str) -> Result<Uuid, <Uuid as TryFrom<&str>>::Error>

Performs the conversion.
Source§

impl TryFrom<Vec<u8>> for Uuid

Source§

type Error = Error

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

fn try_from(value: Vec<u8>) -> Result<Uuid, <Uuid as TryFrom<Vec<u8>>>::Error>

Performs the conversion.
Source§

impl UpperHex for Uuid

Source§

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

Formats the value using the given formatter. Read more
§

impl<P> UriDisplay<P> for Uuid
where P: Part,

This implementation is identical to the Display implementation.

§

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

Formats self in a URI-safe manner using the given formatter.
Source§

impl Copy for 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<'a, T> AsTaggedExplicit<'a> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self>

Source§

impl<'a, T> AsTaggedImplicit<'a> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self>

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, dst: *mut u8)

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

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
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<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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'v, T> FromForm<'v> for T
where T: FromFormField<'v>,

Source§

type Context = FromFieldContext<'v, T>

The form guard’s parsing context.
Source§

fn init(opts: Options) -> <T as FromForm<'v>>::Context

Initializes and returns the parsing context for Self.
Source§

fn push_value(ctxt: &mut <T as FromForm<'v>>::Context, field: ValueField<'v>)

Processes the value field field.
Source§

fn push_data<'life0, 'life1, 'async_trait>( ctxt: &'life0 mut FromFieldContext<'v, T>, field: DataField<'v, 'life1>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'v: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, T: 'async_trait,

Processes the data field field.
Source§

fn finalize(ctxt: <T as FromForm<'v>>::Context) -> Result<T, Errors<'v>>

Finalizes parsing. Returns the parsed value when successful or collection of Errors otherwise.
Source§

fn push_error(_ctxt: &mut Self::Context, _error: Error<'r>)

Processes the external form or field error _error. Read more
Source§

fn default(opts: Options) -> Option<Self>

Returns a default value, if any, to use when a value is desired and parsing fails. Read more
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.

§

impl<T> IntoCollection<T> for T

§

fn into_collection<A>(self) -> SmallVec<A>
where A: Array<Item = T>,

Converts self into a collection.
§

fn mapped<U, F, A>(self, f: F) -> SmallVec<A>
where F: FnMut(T) -> U, A: Array<Item = U>,

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> Paint for T
where T: ?Sized,

Source§

fn fg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the foreground set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like red() and green(), which have the same functionality but are pithier.

§Example

Set foreground color to white using fg():

use yansi::{Paint, Color};

painted.fg(Color::White);

Set foreground color to white using white().

use yansi::Paint;

painted.white();
Source§

fn primary(&self) -> Painted<&T>

Returns self with the fg() set to Color::Primary.

§Example
println!("{}", value.primary());
Source§

fn fixed(&self, color: u8) -> Painted<&T>

Returns self with the fg() set to Color::Fixed.

§Example
println!("{}", value.fixed(color));
Source§

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the fg() set to Color::Rgb.

§Example
println!("{}", value.rgb(r, g, b));
Source§

fn black(&self) -> Painted<&T>

Returns self with the fg() set to Color::Black.

§Example
println!("{}", value.black());
Source§

fn red(&self) -> Painted<&T>

Returns self with the fg() set to Color::Red.

§Example
println!("{}", value.red());
Source§

fn green(&self) -> Painted<&T>

Returns self with the fg() set to Color::Green.

§Example
println!("{}", value.green());
Source§

fn yellow(&self) -> Painted<&T>

Returns self with the fg() set to Color::Yellow.

§Example
println!("{}", value.yellow());
Source§

fn blue(&self) -> Painted<&T>

Returns self with the fg() set to Color::Blue.

§Example
println!("{}", value.blue());
Source§

fn magenta(&self) -> Painted<&T>

Returns self with the fg() set to Color::Magenta.

§Example
println!("{}", value.magenta());
Source§

fn cyan(&self) -> Painted<&T>

Returns self with the fg() set to Color::Cyan.

§Example
println!("{}", value.cyan());
Source§

fn white(&self) -> Painted<&T>

Returns self with the fg() set to Color::White.

§Example
println!("{}", value.white());
Source§

fn bright_black(&self) -> Painted<&T>

Returns self with the fg() set to Color::BrightBlack.

§Example
println!("{}", value.bright_black());
Source§

fn bright_red(&self) -> Painted<&T>

Returns self with the fg() set to Color::BrightRed.

§Example
println!("{}", value.bright_red());
Source§

fn bright_green(&self) -> Painted<&T>

Returns self with the fg() set to Color::BrightGreen.

§Example
println!("{}", value.bright_green());
Source§

fn bright_yellow(&self) -> Painted<&T>

Returns self with the fg() set to Color::BrightYellow.

§Example
println!("{}", value.bright_yellow());
Source§

fn bright_blue(&self) -> Painted<&T>

Returns self with the fg() set to Color::BrightBlue.

§Example
println!("{}", value.bright_blue());
Source§

fn bright_magenta(&self) -> Painted<&T>

Returns self with the fg() set to Color::BrightMagenta.

§Example
println!("{}", value.bright_magenta());
Source§

fn bright_cyan(&self) -> Painted<&T>

Returns self with the fg() set to Color::BrightCyan.

§Example
println!("{}", value.bright_cyan());
Source§

fn bright_white(&self) -> Painted<&T>

Returns self with the fg() set to Color::BrightWhite.

§Example
println!("{}", value.bright_white());
Source§

fn bg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the background set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like on_red() and on_green(), which have the same functionality but are pithier.

§Example

Set background color to red using fg():

use yansi::{Paint, Color};

painted.bg(Color::Red);

Set background color to red using on_red().

use yansi::Paint;

painted.on_red();
Source§

fn on_primary(&self) -> Painted<&T>

Returns self with the bg() set to Color::Primary.

§Example
println!("{}", value.on_primary());
Source§

fn on_fixed(&self, color: u8) -> Painted<&T>

Returns self with the bg() set to Color::Fixed.

§Example
println!("{}", value.on_fixed(color));
Source§

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the bg() set to Color::Rgb.

§Example
println!("{}", value.on_rgb(r, g, b));
Source§

fn on_black(&self) -> Painted<&T>

Returns self with the bg() set to Color::Black.

§Example
println!("{}", value.on_black());
Source§

fn on_red(&self) -> Painted<&T>

Returns self with the bg() set to Color::Red.

§Example
println!("{}", value.on_red());
Source§

fn on_green(&self) -> Painted<&T>

Returns self with the bg() set to Color::Green.

§Example
println!("{}", value.on_green());
Source§

fn on_yellow(&self) -> Painted<&T>

Returns self with the bg() set to Color::Yellow.

§Example
println!("{}", value.on_yellow());
Source§

fn on_blue(&self) -> Painted<&T>

Returns self with the bg() set to Color::Blue.

§Example
println!("{}", value.on_blue());
Source§

fn on_magenta(&self) -> Painted<&T>

Returns self with the bg() set to Color::Magenta.

§Example
println!("{}", value.on_magenta());
Source§

fn on_cyan(&self) -> Painted<&T>

Returns self with the bg() set to Color::Cyan.

§Example
println!("{}", value.on_cyan());
Source§

fn on_white(&self) -> Painted<&T>

Returns self with the bg() set to Color::White.

§Example
println!("{}", value.on_white());
Source§

fn on_bright_black(&self) -> Painted<&T>

Returns self with the bg() set to Color::BrightBlack.

§Example
println!("{}", value.on_bright_black());
Source§

fn on_bright_red(&self) -> Painted<&T>

Returns self with the bg() set to Color::BrightRed.

§Example
println!("{}", value.on_bright_red());
Source§

fn on_bright_green(&self) -> Painted<&T>

Returns self with the bg() set to Color::BrightGreen.

§Example
println!("{}", value.on_bright_green());
Source§

fn on_bright_yellow(&self) -> Painted<&T>

Returns self with the bg() set to Color::BrightYellow.

§Example
println!("{}", value.on_bright_yellow());
Source§

fn on_bright_blue(&self) -> Painted<&T>

Returns self with the bg() set to Color::BrightBlue.

§Example
println!("{}", value.on_bright_blue());
Source§

fn on_bright_magenta(&self) -> Painted<&T>

Returns self with the bg() set to Color::BrightMagenta.

§Example
println!("{}", value.on_bright_magenta());
Source§

fn on_bright_cyan(&self) -> Painted<&T>

Returns self with the bg() set to Color::BrightCyan.

§Example
println!("{}", value.on_bright_cyan());
Source§

fn on_bright_white(&self) -> Painted<&T>

Returns self with the bg() set to Color::BrightWhite.

§Example
println!("{}", value.on_bright_white());
Source§

fn attr(&self, value: Attribute) -> Painted<&T>

Enables the styling Attribute value.

This method should be used rarely. Instead, prefer to use attribute-specific builder methods like bold() and underline(), which have the same functionality but are pithier.

§Example

Make text bold using attr():

use yansi::{Paint, Attribute};

painted.attr(Attribute::Bold);

Make text bold using using bold().

use yansi::Paint;

painted.bold();
Source§

fn bold(&self) -> Painted<&T>

Returns self with the attr() set to Attribute::Bold.

§Example
println!("{}", value.bold());
Source§

fn dim(&self) -> Painted<&T>

Returns self with the attr() set to Attribute::Dim.

§Example
println!("{}", value.dim());
Source§

fn italic(&self) -> Painted<&T>

Returns self with the attr() set to Attribute::Italic.

§Example
println!("{}", value.italic());
Source§

fn underline(&self) -> Painted<&T>

Returns self with the attr() set to Attribute::Underline.

§Example
println!("{}", value.underline());

Returns self with the attr() set to Attribute::Blink.

§Example
println!("{}", value.blink());

Returns self with the attr() set to Attribute::RapidBlink.

§Example
println!("{}", value.rapid_blink());
Source§

fn invert(&self) -> Painted<&T>

Returns self with the attr() set to Attribute::Invert.

§Example
println!("{}", value.invert());
Source§

fn conceal(&self) -> Painted<&T>

Returns self with the attr() set to Attribute::Conceal.

§Example
println!("{}", value.conceal());
Source§

fn strike(&self) -> Painted<&T>

Returns self with the attr() set to Attribute::Strike.

§Example
println!("{}", value.strike());
Source§

fn quirk(&self, value: Quirk) -> Painted<&T>

Enables the yansi Quirk value.

This method should be used rarely. Instead, prefer to use quirk-specific builder methods like mask() and wrap(), which have the same functionality but are pithier.

§Example

Enable wrapping using .quirk():

use yansi::{Paint, Quirk};

painted.quirk(Quirk::Wrap);

Enable wrapping using wrap().

use yansi::Paint;

painted.wrap();
Source§

fn mask(&self) -> Painted<&T>

Returns self with the quirk() set to Quirk::Mask.

§Example
println!("{}", value.mask());
Source§

fn wrap(&self) -> Painted<&T>

Returns self with the quirk() set to Quirk::Wrap.

§Example
println!("{}", value.wrap());
Source§

fn linger(&self) -> Painted<&T>

Returns self with the quirk() set to Quirk::Linger.

§Example
println!("{}", value.linger());
Source§

fn clear(&self) -> Painted<&T>

👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear(). The clear() method will be removed in a future release.

Returns self with the quirk() set to Quirk::Clear.

§Example
println!("{}", value.clear());
Source§

fn resetting(&self) -> Painted<&T>

Returns self with the quirk() set to Quirk::Resetting.

§Example
println!("{}", value.resetting());
Source§

fn bright(&self) -> Painted<&T>

Returns self with the quirk() set to Quirk::Bright.

§Example
println!("{}", value.bright());
Source§

fn on_bright(&self) -> Painted<&T>

Returns self with the quirk() set to Quirk::OnBright.

§Example
println!("{}", value.on_bright());
Source§

fn whenever(&self, value: Condition) -> Painted<&T>

Conditionally enable styling based on whether the Condition value applies. Replaces any previous condition.

See the crate level docs for more details.

§Example

Enable styling painted only when both stdout and stderr are TTYs:

use yansi::{Paint, Condition};

painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);
Source§

fn new(self) -> Painted<Self>
where Self: Sized,

Create a new Painted with a default Style. Read more
Source§

fn paint<S>(&self, style: S) -> Painted<&Self>
where S: Into<Style>,

Apply a style wholesale to self. Any previous style is replaced. 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> 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>,

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