#![warn(unused)]
#![deny(future_incompatible)]
#![deny(nonstandard_style)]
#![deny(rust_2018_idioms)]
#![allow(non_snake_case)] #![allow(non_camel_case_types)] #![allow(unsafe_code)] #![deny(intra_doc_link_resolution_failure)]
#![warn(clippy::cargo)]
#![warn(clippy::nursery)]
#![warn(clippy::pedantic)]
#![warn(clippy::restriction)]
#![allow(clippy::cast_sign_loss)] #![allow(clippy::cast_precision_loss)] #![allow(clippy::cast_possible_truncation)] #![allow(clippy::cognitive_complexity)] #![allow(clippy::too_many_lines)] #![allow(clippy::as_conversions)]
#![allow(clippy::crosspointer_transmute)] #![allow(clippy::decimal_literal_representation)]
#![allow(clippy::else_if_without_else)]
#![allow(clippy::float_arithmetic)]
#![allow(clippy::float_cmp_const)]
#![allow(clippy::implicit_return)]
#![allow(clippy::indexing_slicing)]
#![allow(clippy::integer_arithmetic)]
#![allow(clippy::integer_division)]
#![allow(clippy::let_underscore_must_use)]
#![allow(clippy::match_bool)] #![allow(clippy::mem_forget)] #![allow(clippy::missing_docs_in_private_items)]
#![allow(clippy::missing_inline_in_public_items)]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::multiple_crate_versions)] #![allow(clippy::non_ascii_literal)]
#![allow(clippy::option_expect_used)]
#![allow(clippy::panic)]
#![allow(clippy::result_expect_used)]
#![allow(clippy::shadow_reuse)]
#![allow(clippy::shadow_same)]
#![allow(clippy::unreachable)]
#![allow(clippy::wildcard_enum_match_arm)]
pub mod filesystem;
pub mod panic;
use std::borrow::Cow;
use std::ffi::{CStr, CString};
use std::os::raw::*;
use std::ptr::null_mut;
#[repr(C)]
pub struct COption<T> {
pub value: T,
pub exists: bool,
}
impl<T, U> From<Option<U>> for COption<T>
where
U: Into<T>,
{
#[inline]
#[must_use]
fn from(other: Option<U>) -> Self {
match other {
Some(v) => Self {
value: v.into(),
exists: true,
},
None => Self {
value: unsafe { std::mem::zeroed() },
exists: false,
},
}
}
}
impl<T> Into<Option<T>> for COption<T> {
#[inline]
#[must_use]
fn into(self) -> Option<T> {
match self.exists {
true => Some(self.value),
false => None,
}
}
}
#[repr(C)]
pub struct CVector<T> {
pub ptr: *mut T,
pub count: libc::size_t,
pub capacity: libc::size_t,
}
impl<T, U> From<Vec<U>> for CVector<T>
where
U: Into<T>,
{
#[inline]
#[must_use]
fn from(other: Vec<U>) -> Self {
let mut converted: Vec<T> = other.into_iter().map(std::convert::Into::into).collect();
let ret = Self {
ptr: converted.as_mut_ptr(),
count: converted.len(),
capacity: converted.capacity(),
};
std::mem::forget(converted);
ret
}
}
impl<T, U> Into<Vec<U>> for CVector<T>
where
T: Into<U>,
{
#[inline]
#[must_use]
fn into(self) -> Vec<U> {
let converted: Vec<T> = unsafe { Vec::from_raw_parts(self.ptr, self.count, self.capacity) };
let other: Vec<U> = converted.into_iter().map(std::convert::Into::into).collect();
other
}
}
#[no_mangle]
pub extern "C" fn bve_init() {
panic::init_panic_handler();
}
fn string_to_owned_ptr(input: &str) -> *mut c_char {
CString::new(input).map(CString::into_raw).unwrap_or(null_mut())
}
unsafe fn owned_ptr_to_string(input: *const c_char) -> String {
CString::from_raw(input as *mut c_char).to_string_lossy().into()
}
unsafe fn unowned_ptr_to_str(input: &*const c_char) -> Cow<'_, str> {
CStr::from_ptr(*input).to_string_lossy()
}
#[bve_derive::c_interface]
pub unsafe extern "C" fn bve_delete_string(ptr: *mut c_char) {
CString::from_raw(ptr);
}
pub mod parse;