Skip to main content

ValueCodecRegistration

Struct ValueCodecRegistration 

Source
pub struct ValueCodecRegistration<D: 'static> { /* private fields */ }
Expand description

One statically linked value-codec implementation.

A registration bundles the stable identifier used for lookup and duplicate detection, a borrowed executable descriptor, and the link-time location the registration was declared at. It is produced by register_value_string_codec! or register_value_bytes_codec! rather than built by hand. Applications may also construct a registration manually from static data and pass it to a local ValueCodecRegistry.

The ID has already been validated by ValueCodecId. The descriptor must live in static storage because registrations borrow it with a 'static lifetime. The source records where the registration came from for duplicate ID diagnostics; it does not affect those static requirements.

The registration macros validate codecs through the matching descriptor. Encoder and decoder error types must implement Error + Send + Sync + 'static; codec and value types do not need those bounds.

Registration macros create these values from codec descriptors and submit them to the process-wide inventory. See register_value_string_codec! and register_value_bytes_codec! for executable registration examples. For a local registry, this type can be constructed directly from a validated ID, a static descriptor, and source information as shown below.

§Type Parameters

  • D: Static descriptor type that executes the registered codec.

§Examples

use qubit_codec::ValueCodecId;
use qubit_codec::ValueCodecRegistration;
use qubit_codec::ValueCodecRegistrationSource;

static DESCRIPTOR: u8 = 1;
let registration = ValueCodecRegistration::new(
    ValueCodecId::new("example.u8"),
    &DESCRIPTOR,
    ValueCodecRegistrationSource::new("qubit-codec", "example", "src/example.rs", 1),
);
assert_eq!(registration.id().as_str(), "example.u8");
assert_eq!(*registration.descriptor(), 1);

Implementations§

Source§

impl<D: 'static> ValueCodecRegistration<D>

Source

pub const fn new( id: ValueCodecId, descriptor: &'static D, source: ValueCodecRegistrationSource, ) -> Self

Creates a registration from the validated facts captured by a registration macro.

Use the registration macros to submit a codec to the process-wide inventory. For a local registry, construct this value from static data and pass a reference to ValueCodecRegistry::from_registrations. The ID must already be validated, and the descriptor must have static storage. The source provides location details for duplicate-ID diagnostics.

§Parameters
  • id: Stable identifier used for registry lookup and duplicate detection.
  • descriptor: Descriptor in static storage that performs codec operations.
  • source: Declaration location captured by the registration macro.
§Returns

A copyable registration borrowing the static descriptor.

Source

pub const fn id(&self) -> ValueCodecId

Returns the stable value-codec ID used by registry lookups.

§Returns

The registration’s validated, copyable identifier.

Source

pub const fn descriptor(&self) -> &'static D

Returns the descriptor used to execute this codec.

§Returns

A static borrow of the descriptor associated with this registration.

Source

pub const fn source(&self) -> ValueCodecRegistrationSource

Returns the source location captured at the registration declaration.

§Returns

The copyable package, module, file, and line information for this registration.

Trait Implementations§

Source§

impl<D: Clone + 'static> Clone for ValueCodecRegistration<D>

Source§

fn clone(&self) -> Self

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<D: Copy + 'static> Copy for ValueCodecRegistration<D>

Source§

impl<D: Debug + 'static> Debug for ValueCodecRegistration<D>

Source§

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

Formats the value using the given formatter. Read more

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.