[][src]Struct pir_8_emu::binutils::pir_8_as::OutputWithQueue

pub struct OutputWithQueue { /* fields omitted */ }

Output sink which transparently waits for labels to be saved

Examples

let mut dest = vec![];
let mut output = OutputWithQueue::new(&mut dest);
let mut labels = BTreeMap::new();

output.write_all(&[0xFE], &labels).unwrap();
assert_eq!(&dest, &[0xFEu8]);

output.wait_for_label("OwO".to_string(), 0, LabelFragment::Full);
output.write_all(&[0xFF], &labels).unwrap();
assert_eq!(&dest, &[0xFEu8]);

output.wait_for_label("OwO".to_string(), 0x0F, LabelFragment::Low);
output.write_all(&[0xFF], &labels).unwrap();
assert_eq!(&dest, &[0xFEu8]);

output.wait_for_label("eWe".to_string(), 0, LabelFragment::Full);
output.write_all(&[0x4C], &labels).unwrap();
assert_eq!(&dest, &[0xFEu8]);

output.wait_for_label("ЦшЦ".to_string(), 0, LabelFragment::Full);
output.write_all(&[0xEC], &labels).unwrap();
assert_eq!(&dest, &[0xFEu8]);

labels.insert("OwO".to_string(), 0x0110);
labels.insert("ЦшЦ".to_string(), 0x0420);
output.write_all(&[0xFA], &labels).unwrap();
assert_eq!(&dest, &[0xFEu8, 0x01, 0x10, 0xFF, 0x1F, 0xFF]);

assert_eq!(output.unfound_labels(&labels), Some(vec!["eWe".to_string()].into_iter().collect()));

Methods

impl OutputWithQueue[src]

pub fn new<W: Write + 'static>(output: W) -> OutputWithQueue[src]

Create an unqueued output, writing to the specified destination

pub fn wait_for_label(
    &mut self,
    label: String,
    offset: i16,
    fragment: LabelFragment
)
[src]

Queue all output going forward until a label with the specified name shows up, and offset it by the specified amount

pub fn write_all(
    &mut self,
    buf: &[u8],
    labels: &BTreeMap<String, u16>
) -> Result<()>
[src]

Write the specified bytes to the output or queue them

Calls flush() first

If afterward, the label buffer is not empty, queue the specified buffer at the end

Otherwise, write the specified buffer directly to the output device

pub fn flush(&mut self, labels: &BTreeMap<String, u16>) -> Result<()>[src]

Attempt to clear the label queue

There's no need to call this explicitly, as write_all() will call this funxion before performing any output

If the label at the front of the queue is present in the specified labelset write its address, then the buffer queued behind it, and pop it off

This repeats until the queue is empty or the label thereatfront doesn't exist in the labelset

pub fn unfound_labels(
    self,
    labels: &BTreeMap<String, u16>
) -> Option<BTreeSet<String>>
[src]

Get all remaining queued labels not present in the specified labelset, or None if all were

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Downcast for T where
    T: Any
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.