Macro empty_virtual_extension

Source
macro_rules! empty_virtual_extension {
    (
        target: $target:ty,
        tag: $extension:ty,
        schema: static $schema:ty
        $(, generics: [$($gen:tt),* $(,)? ])?
        $(, bounds: [$($extra_bounds:tt)*])?
        $(,)?
    ) => { ... };
    (
        target: $target:ty,
        tag: $extension:ty,
        schema: $schema:ty
        $(, generics: [$($gen:tt),* $(,)? ])?
        $(, bounds: [$($extra_bounds:tt)*])?
        $(,)?
    ) => { ... };
}
Expand description

Implements an empty virtual extension schema for a given extension.

This macro defines a no-op schema where the extension has no storage and behaves as absent.

It supports two modes:

  • Dynamic (default) -> implements VirtualDynExtensionSchema

    • uses vector-like semantics (Vec<()>)
    • size-related operations (len, min, max) return 0
  • Static (static keyword) -> implements VirtualStaticExtensionSchema

    • uses array-like semantics ([(); 0])
    • fully determined at compile time
    • no size-related operations are required

§Semantics

In both modes:

  • None, Some, and Repr are represented as ()
  • no data is stored
  • the extension is effectively non-existent

This is useful when:

  • a container participates in the extension system
  • but a particular extension is unsupported or intentionally omitted

§Syntax

§Dynamic (default)

empty_virtual_extension!(
    target: MyContainer,
    tag: MyExtension,
    schema: MySchema,
    generics: [T, U],
    bounds: [T: Clone, U: Default],
);

§Static

empty_virtual_extension!(
    target: MyContainer,
    tag: MyExtension,
    schema: static MySchema,
);

§Parameters

  • target: container type (conceptual owner of the extension)
  • tag: discriminant identifying the extension
  • schema: schema type to implement
  • generics (optional): generics for the impl
  • bounds (optional): additional where constraints

§Behavior

  • The extension is treated as non-existent
  • Dynamic mode:
    • uses Vec<()> (always empty)
    • returns 0 for all size queries
  • Static mode:
    • uses [(); 0] (zero-length array)
    • fully resolved at compile time