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

vortex-data / vortex / 16935267080

13 Aug 2025 11:00AM UTC coverage: 24.312% (-63.3%) from 87.658%
16935267080

Pull #4226

github

web-flow
Merge 81b48c7fb into baa6ea202
Pull Request #4226: Support converting TimestampTZ to and from duckdb

0 of 2 new or added lines in 1 file covered. (0.0%)

20666 existing lines in 469 files now uncovered.

8726 of 35892 relevant lines covered (24.31%)

147.74 hits per line

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

0.0
/vortex-buffer/src/string.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use std::fmt::{Debug, Formatter};
5
use std::ops::Deref;
6
use std::str::Utf8Error;
7

8
use crate::ByteBuffer;
9

10
/// A wrapper around a [`ByteBuffer`] that guarantees that the buffer contains valid UTF-8.
11
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
12
pub struct BufferString(ByteBuffer);
13

14
impl BufferString {
15
    /// Creates a new `BufferString` from a [`ByteBuffer`].
16
    ///
17
    /// # Safety
18
    /// Assumes that the buffer contains valid UTF-8.
UNCOV
19
    pub const unsafe fn new_unchecked(buffer: ByteBuffer) -> Self {
×
UNCOV
20
        Self(buffer)
×
UNCOV
21
    }
×
22

23
    /// Return a view of the contents of BufferString as an immutable `&str`.
UNCOV
24
    pub fn as_str(&self) -> &str {
×
25
        // SAFETY: We have already validated that the buffer is valid UTF-8
UNCOV
26
        unsafe { std::str::from_utf8_unchecked(self.0.as_ref()) }
×
UNCOV
27
    }
×
28

29
    /// Returns the inner [`ByteBuffer`].
UNCOV
30
    pub fn into_inner(self) -> ByteBuffer {
×
UNCOV
31
        self.0
×
UNCOV
32
    }
×
33

34
    /// Returns reference to the inner [`ByteBuffer`].
UNCOV
35
    pub fn inner(&self) -> &ByteBuffer {
×
UNCOV
36
        &self.0
×
UNCOV
37
    }
×
38
}
39

40
impl Debug for BufferString {
UNCOV
41
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
×
UNCOV
42
        f.debug_struct("BufferString")
×
UNCOV
43
            .field("string", &self.as_str())
×
UNCOV
44
            .finish()
×
UNCOV
45
    }
×
46
}
47

48
impl From<BufferString> for ByteBuffer {
49
    fn from(value: BufferString) -> Self {
×
50
        value.0
×
51
    }
×
52
}
53

54
impl From<String> for BufferString {
UNCOV
55
    fn from(value: String) -> Self {
×
UNCOV
56
        Self(ByteBuffer::from(value.into_bytes()))
×
UNCOV
57
    }
×
58
}
59

60
impl From<&str> for BufferString {
UNCOV
61
    fn from(value: &str) -> Self {
×
UNCOV
62
        Self(ByteBuffer::from(String::from(value).into_bytes()))
×
UNCOV
63
    }
×
64
}
65

66
impl TryFrom<ByteBuffer> for BufferString {
67
    type Error = Utf8Error;
68

UNCOV
69
    fn try_from(value: ByteBuffer) -> Result<Self, Self::Error> {
×
UNCOV
70
        let _ = std::str::from_utf8(value.as_ref())?;
×
UNCOV
71
        Ok(Self(value))
×
UNCOV
72
    }
×
73
}
74

75
impl Deref for BufferString {
76
    type Target = str;
77

UNCOV
78
    fn deref(&self) -> &Self::Target {
×
UNCOV
79
        self.as_str()
×
UNCOV
80
    }
×
81
}
82

83
impl AsRef<str> for BufferString {
UNCOV
84
    fn as_ref(&self) -> &str {
×
UNCOV
85
        self.as_str()
×
UNCOV
86
    }
×
87
}
88

89
impl AsRef<[u8]> for BufferString {
UNCOV
90
    fn as_ref(&self) -> &[u8] {
×
UNCOV
91
        self.as_str().as_bytes()
×
UNCOV
92
    }
×
93
}
94

95
#[cfg(test)]
96
mod test {
97
    use crate::{Alignment, BufferString, buffer};
98

99
    #[test]
100
    fn buffer_string() {
101
        let buf = BufferString::from("hello");
102
        assert_eq!(buf.len(), 5);
103
        assert_eq!(buf.into_inner().alignment(), Alignment::of::<u8>());
104
    }
105

106
    #[test]
107
    fn buffer_string_non_ut8() {
108
        assert!(BufferString::try_from(buffer![0u8, 255]).is_err());
109
    }
110
}
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