aboutsummaryrefslogtreecommitdiff
path: root/ffi/src/write_sink.rs
blob: b1884985ae91c8831e2b416329259347e7060351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
pub struct InstructionSink<'buf> {
    pub buf: &'buf mut [u8],
    pub offs: usize,
}

impl<'a> core::fmt::Write for InstructionSink<'a> {
    fn write_str(&mut self, s: &str) -> core::fmt::Result {
        for b in s.bytes() {
            if self.offs < self.buf.len() {
                self.buf[self.offs] = b;
                self.offs += 1;
            } else {
                break;
            }
        }

        Ok(())
    }
}