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
Label
s can be set to point to other Label
s, 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
.
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.
Subtract a constant from a Label
, producing a new Label
.
The new Label
references the existing Label
.
Auto Trait Implementations
impl !RefUnwindSafe for Label
impl !UnwindSafe for Label
Blanket Implementations
Mutably borrows from an owned value. Read more