use std::{
ffi::{CString, c_int},
fmt::Display,
};
use crate::bindings::{vnet_error, vnet_error_t};
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct VnetError(vnet_error_t);
impl VnetError {
pub fn context<M: Display>(self, message: M) -> crate::vppinfra::error::ErrorStack {
unsafe {
let message_c = CString::new(message.to_string())
.expect("message should not contain nul terminator");
let ptr = vnet_error(self.0, c"%s".as_ptr().cast_mut().cast(), message_c.as_ptr());
crate::vppinfra::error::ErrorStack::from_raw(ptr)
}
}
}
impl From<c_int> for VnetError {
fn from(value: c_int) -> Self {
Self(value)
}
}
impl From<VnetError> for i32 {
fn from(value: VnetError) -> Self {
value.0
}
}
pub const VNET_ERR_INVALID_ARGUMENT: VnetError = VnetError(-73);