1
0
Files
wfassoc/wfassoc-cdylib/src/lib.rs

59 lines
1.2 KiB
Rust
Raw Normal View History

use std::cell::RefCell;
use std::ffi::{CString, c_char};
use thiserror::Error as TeError;
2025-11-26 22:40:17 +08:00
mod last_error;
mod string_cache;
2026-01-04 14:05:34 +08:00
mod wrapper;
2025-11-26 22:40:17 +08:00
// region: Error
/// Error occurs in this crate.
#[derive(Debug, TeError)]
enum Error {
/// Error occurs in wfassoc core.
#[error("{0}")]
Core(#[from] wfassoc::Error),
#[error("error occurs when parsing into C/C++ string")]
CastIntoCStr(#[from] std::ffi::NulError),
#[error("error occurs when parsing from C/C++ string")]
CastFromCStr(#[from] std::ffi::IntoStringError),
}
/// Result type used in this crate.
type Result<T> = std::result::Result<T, Error>;
// endregion
// region: Macros
// endregion
2025-10-18 09:55:08 +08:00
#[unsafe(no_mangle)]
pub extern "C" fn WFStartup() -> bool {
false
}
#[unsafe(no_mangle)]
pub extern "C" fn WFShutdown() -> bool {
false
}
#[unsafe(no_mangle)]
pub extern "C" fn WFGetLastError() -> *const c_char {
2025-11-26 22:40:17 +08:00
last_error::get_last_error()
}
#[unsafe(no_mangle)]
pub extern "C" fn WFHasPrivilege() -> bool {
wfassoc::utilities::has_privilege()
}
#[unsafe(no_mangle)]
pub extern "C" fn WFAdd(left: u32, right: u32, rv: *mut u32) -> bool {
unsafe { *rv = left + right; }
return true;
}