• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

adierking / unplug / 15940344048

28 Jun 2025 04:12AM UTC coverage: 77.613%. First build
15940344048

push

github

adierking
hsd: Vertex data

0 of 109 new or added lines in 6 files covered. (0.0%)

20344 of 26212 relevant lines covered (77.61%)

1089927.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/unplug/src/hsd/buffer.rs
1
use super::pointer::{DefaultIn, NodeBase, ReadPointerBase};
2
use super::{Node, Pointer, ReadPointer, Result};
3
use bumpalo::collections::Vec;
4
use bumpalo::Bump;
5
use std::ops::{Deref, DerefMut};
6

7
/// A variable-size byte buffer.
8
///
9
/// This is not compatible with `read_pointer()`. Use `Buffer::read_pointer_unknown_size()` or
10
/// `Buffer::read_pointer_known_size()` to read a pointer to a buffer.
11
#[derive(Clone, PartialEq, Eq)]
×
12
pub struct Buffer<'a> {
13
    bytes: Vec<'a, u8>,
14
}
15

16
impl<'a> std::fmt::Debug for Buffer<'a> {
17
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
×
18
        f.debug_struct("Buffer").field("size", &self.bytes.len()).finish()
×
19
    }
×
20
}
21

22
impl<'a> Buffer<'a> {
23
    /// Create an empty buffer in an arena.
24
    pub fn new_in(arena: &'a Bump) -> Self {
×
NEW
25
        Self { bytes: bumpalo::vec![in arena] }
×
26
    }
×
27

28
    /// Create a buffer in an arena with a known maximum size.
29
    pub fn with_size_in(arena: &'a Bump, size: usize) -> Self {
×
NEW
30
        Self { bytes: bumpalo::vec![in arena; 0; size] }
×
31
    }
×
32

33
    /// Read a pointer to a buffer with an unknown size.
NEW
34
    pub fn read_pointer_unknown_size<R>(reader: &mut R) -> Result<Pointer<'a, Self>>
×
NEW
35
    where
×
NEW
36
        R: ReadPointer<'a> + ?Sized,
×
NEW
37
    {
×
NEW
38
        reader.read_pointer_into(Self::new_in(reader.arena()))
×
NEW
39
    }
×
40

41
    /// Read a pointer to a buffer with a known size.
NEW
42
    pub fn read_pointer_known_size<R>(reader: &mut R, size: usize) -> Result<Pointer<'a, Self>>
×
43
    where
×
44
        R: ReadPointer<'a> + ?Sized,
×
45
    {
×
46
        reader.read_pointer_into(Self::with_size_in(reader.arena(), size))
×
47
    }
×
48
}
49

50
impl<'a> DefaultIn<'a> for Buffer<'a> {
51
    fn default_in(arena: &'a Bump) -> Self {
×
52
        Self::new_in(arena)
×
53
    }
×
54
}
55

56
impl Deref for Buffer<'_> {
57
    type Target = [u8];
58
    fn deref(&self) -> &Self::Target {
×
59
        &self.bytes
×
60
    }
×
61
}
62

63
impl DerefMut for Buffer<'_> {
64
    fn deref_mut(&mut self) -> &mut Self::Target {
×
65
        &mut self.bytes
×
66
    }
×
67
}
68

69
// Manual impl of NodeBase; we can't use ReadFrom because the buffer needs to have a size assigned.
70
impl<'a> NodeBase<'a> for Buffer<'a> {
NEW
71
    fn read<'r>(&mut self, reader: &'r mut dyn ReadPointerBase<'a>, max_size: usize) -> Result<()> {
×
NEW
72
        if self.bytes.is_empty() {
×
NEW
73
            self.bytes.resize(max_size, 0);
×
NEW
74
        }
×
75
        reader.read_exact(&mut self.bytes)?;
×
76
        Ok(())
×
77
    }
×
78
}
79

80
impl<'a> Node<'a> for Buffer<'a> {}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc