Struct rust_examples::adts::SelfReferentialStructureTest[][src]

pub struct SelfReferentialStructureTest;
Expand description

This test demonstrates that in Rust all self-referential structures must have size known at compile time. This means that such structures cannot own data of type Self but rather have to indirectly refence these via some sort of a pointer.

Example

enum PList<T> {
    Nil,
    Cons(T, Self),
}

In order to make the example above compile, one would have to use some sort of indirection for the Self owned by the Cons variant. This indirection can be realized by either

  • a refence to stack-allocated data (&)
  • a refence to heap-allocated data (Box)
  • a refence counting pointer (std::rc::Rc)

or similar pointer-like structure which has defined size - i.e. is known not to be infinite (of unbounded memory).

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.