Compare commits

...
2 Commits
Author SHA1 Message Date
neo 0cb4086729 added array inclusion in lib.rs 2026-08-24 19:34:00 +02:00
neo ae0fe2aa44 added array bindings 2026-08-24 19:30:32 +02:00
2 changed files with 50 additions and 1 deletions
+46
View File
@@ -0,0 +1,46 @@
use std::io::{Error, ErrorKind, Result};
use std::ptr::NonNull;
use crate::ffi::wl_array;
use crate::ffi::{wl_array_add, wl_array_copy, wl_array_init, wl_array_release};
pub struct Array {
raw: NonNull<wl_array>,
}
impl Array {
pub fn new() -> Result<Self> {
let raw: *mut wl_array = std::ptr::null_mut();
unsafe { wl_array_init(raw) };
Ok(Self { raw: NonNull::new(raw).unwrap() })
}
/// Increases the size of the array by size bytes
///
/// * `size` - Number of bytes to increase the size of the array by
pub fn add(&self, size: usize) -> Result<()> {
let ptr = unsafe { wl_array_add(self.raw.as_ptr(), size) };
if ptr.is_null() {
return Err(Error::new(ErrorKind::OutOfMemory, "unable to resize array"));
}
Ok(())
}
/// Copies the contents of `source` to this `array`
///
/// * `source` - Source array to copy from
pub fn copy(&self, source: &mut Array) -> Result<()> {
let ret = unsafe { wl_array_copy(self.raw.as_ptr(), source.raw.as_ptr()) };
if ret != 0 {
return Err(Error::new(ErrorKind::Other, "unable to copy array"));
}
Ok(())
}
/// Release the array data
/// Leaves the array in an invalid state
pub fn release(&self) {
unsafe { wl_array_release(self.raw.as_ptr()) };
}
}
+3
View File
@@ -1,3 +1,6 @@
#![feature(c_variadic)] #![feature(c_variadic)]
pub(crate) mod ffi; pub(crate) mod ffi;
// public api
pub mod array;