Struct test_assembler::Label[][src]

pub struct Label(pub Rc<RealLabel>);
Expand description

A Label represents a value not yet known that is stored in a Section.

As long as all the labels a section refers to are defined by the time its contents are retrieved as bytes, undefined labels can be used freely in that section’s construction. A label can be in one of three states:

  • undefined,
  • defined as the sum of some other label and a constant, or
  • a constant.

A label’s value never changes, but it can accumulate constraints. Adding labels and integers is permitted, and yields a label. Subtracting a constant from a label is permitted, and also yields a label. Subtracting two labels that have some relationship to each other is permitted, and yields a constant.

A common usage of Label is to use Section::mark to make a Label contain an offset into the Section without having to hard-code it. The Section methods for inserting fixed-width integer values (such as Section::L32) all accept &Label for the purpose of writing a value that is not yet available.

Examples

Labels can be set to point to other Labels, potentially with an offset.

use test_assembler::*;

let l1 = Label::new();
// l2 is l1's value (which is currently undefined) + 10
let l2 = &l1 + 10;
// Now give l1 a value.
l1.set_const(1);
// l2's value is derived from l1.
assert_eq!(l2.value().unwrap(), 11);

Tuple Fields

0: Rc<RealLabel>

Trait Implementations

Add a constant to a Label, producing a new Label.

The new Label references the existing Label.

The resulting type after applying the + operator.

Performs the + operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Create an undefined label.

Create a label with a constant value val.

Create a label whose value is equal to other.

Create a label whose value is equal to other plus offset.

Subtract a Label from another Label, returning an i64.

If the labels are unrelated this will panic.

The resulting type after applying the - operator.

Performs the - operation. Read more

Subtract a constant from a Label, producing a new Label.

The new Label references the existing Label.

The resulting type after applying the - operator.

Performs the - operation. Read more

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 resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.