-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput.rs
More file actions
36 lines (29 loc) · 761 Bytes
/
output.rs
File metadata and controls
36 lines (29 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use crate::*;
// TODO should we make no-panic guarantees like reader::Input ?
// before this, Output does not need to be unsafe
pub trait Output: Default {
type Storage: ByteStorage; // ?
fn byte(&mut self, n: u8);
fn bytes<B: AsRef<[u8]>>(&mut self, bytes: B);
fn leak(self) -> Self::Storage;
}
#[cfg(feature = "alloc")]
#[derive(Default)]
pub struct VecOutput {
bytes: Vec<u8>,
}
#[cfg(feature = "alloc")]
impl Output for VecOutput {
type Storage = Vec<u8>;
#[inline]
fn byte(&mut self, n: u8) {
self.bytes.push(n);
}
#[inline]
fn bytes<B: AsRef<[u8]>>(&mut self, bytes: B) {
self.bytes.extend_from_slice(bytes.as_ref());
}
fn leak(self) -> Self::Storage {
self.bytes
}
}