declared interfaces and more wrappers
This commit is contained in:
+49
@@ -0,0 +1,49 @@
|
||||
// SPDX: GPL-2.0-only
|
||||
|
||||
use std::io;
|
||||
use std::ptr::NonNull;
|
||||
use crate::Wrapper;
|
||||
use crate::ffi::wl_list;
|
||||
use crate::ffi::{
|
||||
wl_list_init, wl_list_insert, wl_list_insert_list,
|
||||
wl_list_empty, wl_list_length, wl_list_remove,
|
||||
};
|
||||
|
||||
pub struct List {
|
||||
raw: NonNull<wl_list>,
|
||||
}
|
||||
impl List {
|
||||
pub fn new() -> io::Result<Self> {
|
||||
let list = std::ptr::null_mut();
|
||||
unsafe { wl_list_init(list) };
|
||||
|
||||
let Some(raw) = NonNull::new(list) else {
|
||||
return Err(io::Error::last_os_error());
|
||||
};
|
||||
|
||||
Ok(Self { raw })
|
||||
}
|
||||
pub fn insert(&self, elm: &List) {
|
||||
unsafe { wl_list_insert(self.as_raw_ptr(), elm.as_raw_ptr()) };
|
||||
}
|
||||
pub fn insert_list(&self, other: &List) {
|
||||
unsafe { wl_list_insert_list(self.as_raw_ptr(), other.as_raw_ptr()) };
|
||||
}
|
||||
pub fn length(&self) -> usize {
|
||||
let length = unsafe { wl_list_length(self.as_raw_ptr())};
|
||||
length
|
||||
}
|
||||
pub fn empty(&self) -> bool {
|
||||
let ret: bool = unsafe { wl_list_empty(self.as_raw_ptr()) };
|
||||
ret
|
||||
}
|
||||
pub fn remove(&self, elm: &List) {
|
||||
unsafe { wl_list_remove(elm.as_raw_ptr()) };
|
||||
}
|
||||
}
|
||||
impl Wrapper for List {
|
||||
type T = wl_list;
|
||||
fn get_raw(&self) -> std::ptr::NonNull<Self::T> {
|
||||
self.raw
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user