1 //! small utilities used in tests
2 
3 use crate::{FontData, Scalar};
4 
5 /// A convenience type for generating a buffer of big-endian bytes.
6 #[derive(Debug, Clone, Default)]
7 pub struct BeBuffer(Vec<u8>);
8 
9 impl BeBuffer {
new() -> Self10     pub fn new() -> Self {
11         Default::default()
12     }
13 
14     /// Write any scalar to this buffer.
push(mut self, item: impl Scalar) -> Self15     pub fn push(mut self, item: impl Scalar) -> Self {
16         self.0.extend(item.to_raw().as_ref());
17         self
18     }
19 
20     /// Write multiple scalars into the buffer
extend<T: Scalar>(mut self, iter: impl IntoIterator<Item = T>) -> Self21     pub fn extend<T: Scalar>(mut self, iter: impl IntoIterator<Item = T>) -> Self {
22         for item in iter {
23             self.0.extend(item.to_raw().as_ref());
24         }
25         self
26     }
27 
font_data(&self) -> FontData28     pub fn font_data(&self) -> FontData {
29         FontData::new(&self.0)
30     }
31 }
32 
33 impl std::ops::Deref for BeBuffer {
34     type Target = [u8];
deref(&self) -> &Self::Target35     fn deref(&self) -> &Self::Target {
36         &self.0
37     }
38 }
39