Skip to content

Commit 6cc7a0b

Browse files
committed
feat(sys): implement as_bytes() on variable values
1 parent 8241ebc commit 6cc7a0b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

nginx-sys/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ impl ngx_module_t {
9898
}
9999
}
100100

101+
impl ngx_variable_value_t {
102+
/// Returns the contents of this variable value as a byte slice.
103+
pub fn as_bytes(&self) -> &[u8] {
104+
match self.len() {
105+
0 => &[],
106+
// SAFETY: data for non-empty value must be a valid well-aligned pointer.
107+
len => unsafe { core::slice::from_raw_parts(self.data, len as usize) },
108+
}
109+
}
110+
}
111+
112+
impl AsRef<[u8]> for ngx_variable_value_t {
113+
fn as_ref(&self) -> &[u8] {
114+
self.as_bytes()
115+
}
116+
}
117+
101118
/// Returns the error code of the last failed operation (`errno`).
102119
#[inline]
103120
pub fn ngx_errno() -> ngx_err_t {

0 commit comments

Comments
 (0)