Skip to main content

KafkaUuid

Struct KafkaUuid 

Source
pub struct KafkaUuid(pub Uuid);
Expand description

A Kafka Uuid: a cluster id, topic id, or log-directory id.

This is the value type of org.apache.kafka.common.Uuid. Kafka prints these ids as 22 characters of unpadded base64url, for example UXyU9i5ARn6W00ON2taeWA, not as the hyphenated hex form that uuid::Uuid prints. Display and FromStr use the Kafka form. So does serde, which always writes the id as that string.

FromStr matches Uuid.fromString in Apache Kafka 4.3.1. It accepts exactly the inputs that Kafka accepts and gives the same error messages. Two consequences are not obvious:

  • Kafka ignores the unused low bits of the last character, so _____________________x parses to the same id as _____________________w.
  • Kafka also accepts the 22 characters followed by ==.

Parsing never rejects a reserved id. Kafka’s fromString does not reject them, and kafka-storage format --cluster-id stores any string. Check is_reserved where a caller must refuse one.

The ordering is Kafka’s compareTo: it compares the two halves as signed 64-bit integers, most significant half first. This is not the unsigned byte order of uuid::Uuid.

§Examples

use krabka_ids::KafkaUuid;

let id: KafkaUuid = "UXyU9i5ARn6W00ON2taeWA".parse()?;
assert2::assert!(id.to_string() == "UXyU9i5ARn6W00ON2taeWA");
assert2::assert!(KafkaUuid::METADATA_TOPIC_ID.to_string() == "AAAAAAAAAAAAAAAAAAAAAQ");

Tuple Fields§

§0: Uuid

Implementations§

Source§

impl KafkaUuid

Source

pub const ZERO: Self

The id that stands for a null or empty id (Kafka’s ZERO_UUID).

Source

pub const ONE: Self

The reserved id with value one (Kafka’s ONE_UUID).

Source

pub const METADATA_TOPIC_ID: Self = Self::ONE

The topic id of the metadata topic, __cluster_metadata.

Source

pub const RESERVED: [Self; 2]

The ids that random never returns (Kafka’s Uuid.RESERVED).

Source

pub const DIRECTORY_MIGRATING: Self = Self::ZERO

The directory id of a replica that is in a log directory that the broker has not yet reported (Kafka’s DirectoryId.MIGRATING).

Source

pub const DIRECTORY_UNASSIGNED: Self = Self::ONE

The directory id of a replica that is not yet placed in a log directory (Kafka’s DirectoryId.UNASSIGNED).

Source

pub const DIRECTORY_LOST: Self

The directory id of a replica in an offline log directory that has no known id (Kafka’s DirectoryId.LOST).

Source

pub const fn from_bits(most_significant: i64, least_significant: i64) -> Self

Builds an id from its two halves, as Kafka’s Uuid(long, long) does.

Source

pub const fn get(self) -> Uuid

The inner uuid::Uuid.

Source

pub const fn most_significant_bits(self) -> i64

The most significant 64 bits, as Kafka’s getMostSignificantBits returns them.

Source

pub const fn least_significant_bits(self) -> i64

The least significant 64 bits, as Kafka’s getLeastSignificantBits returns them.

Source

pub fn random() -> Self

Returns a random version 4 id, as Kafka’s Uuid.randomUuid does.

The result is never in RESERVED, and its string form never starts with -. A leading - would make a command-line parser read the id as an option.

Source

pub fn random_directory_id() -> Self

Returns a random log-directory id, as Kafka’s DirectoryId.random does.

The result obeys the rules of random, and it is never one of the 100 reserved directory ids (see is_reserved_directory_id).

Source

pub fn is_reserved(self) -> bool

Returns true for an id in RESERVED.

Source

pub const fn is_reserved_directory_id(self) -> bool

Returns true for one of the 100 lowest ids, which Kafka reserves as directory ids (Kafka’s DirectoryId.reserved).

Source

pub fn parse_kafka_or_hyphenated(input: &str) -> Result<Self, KafkaUuidError>

Parses the Kafka form, or the 36-character hyphenated hex form.

Kafka’s Uuid.fromString rejects the hyphenated form, so FromStr does too. Krabka’s own tools also accept it, and they parse through this function. An input with a - at each of the four hyphen positions of a 36-character string is parsed as hex. Any other input is parsed as FromStr parses it.

§Errors

Returns KafkaUuidError::Hyphenated when the input has the shape of the hyphenated form but is not valid hex. Otherwise returns the error of FromStr.

Trait Implementations§

Source§

impl Clone for KafkaUuid

Source§

fn clone(&self) -> KafkaUuid

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for KafkaUuid

Source§

impl Debug for KafkaUuid

Source§

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

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

impl Default for KafkaUuid

Source§

fn default() -> KafkaUuid

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

impl<'de> Deserialize<'de> for KafkaUuid

Source§

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

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

impl Display for KafkaUuid

Source§

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

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

impl Eq for KafkaUuid

Source§

impl From<KafkaUuid> for Uuid

Source§

fn from(value: KafkaUuid) -> Self

Converts to this type from the input type.
Source§

impl From<Uuid> for KafkaUuid

Source§

fn from(value: Uuid) -> Self

Converts to this type from the input type.
Source§

impl FromStr for KafkaUuid

Source§

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

Parses the Kafka form, as Kafka’s Uuid.fromString does.

Source§

type Err = KafkaUuidError

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

impl Hash for KafkaUuid

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 Ord for KafkaUuid

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · 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 KafkaUuid

Source§

fn eq(&self, other: &KafkaUuid) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 KafkaUuid

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 KafkaUuid

Source§

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

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

impl StructuralPartialEq for KafkaUuid

Auto Trait Implementations§

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

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.