Struct Label

Source
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§

Source§

impl<'a> Add<i64> for &'a Label

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

The new Label references the existing Label.

Source§

type Output = Label

The resulting type after applying the + operator.
Source§

fn add(self, rhs: i64) -> Label

Performs the + operation. Read more
Source§

impl Clone for Label

Source§

fn clone(&self) -> Label

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Label

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Deref for Label

Source§

type Target = RealLabel

The resulting type after dereferencing.
Source§

fn deref(&self) -> &RealLabel

Dereferences the value.
Source§

impl LabelMaker for Label

Source§

fn new() -> Label

Create an undefined label.
Source§

fn from_const(val: u64) -> Label

Create a label with a constant value val.
Source§

fn from_label(other: &Label) -> Label

Create a label whose value is equal to other.
Source§

fn from_label_offset(other: &Label, offset: i64) -> Label

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

impl<'a> Sub<i64> for &'a Label

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

The new Label references the existing Label.

Source§

type Output = Label

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: i64) -> Label

Performs the - operation. Read more
Source§

impl<'a> Sub for &'a Label

Subtract a Label from another Label, returning an i64.

If the labels are unrelated this will panic.

Source§

type Output = i64

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &'a Label) -> i64

Performs the - operation. Read more
Source§

impl<'a, T: Num> ToLabelOrNum<'a, T> for &'a Label

Source§

impl<'a, T: Num> ToLabelOrNum<'a, T> for Label

Auto Trait Implementations§

§

impl Freeze for Label

§

impl !RefUnwindSafe for Label

§

impl !Send for Label

§

impl !Sync for Label

§

impl Unpin for Label

§

impl !UnwindSafe for Label

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.