mirror of https://github.com/tailix/libkernaux.git
Rust: start writing binding
This commit is contained in:
parent
ee21cb49b0
commit
fec9f96ccc
|
@ -13,3 +13,4 @@ categories = ["api-bindings", "embedded", "external-ffi-bindings", "no-std", "pa
|
|||
publish = true
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2.113"
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
max_width = 80
|
|
@ -1,8 +1,24 @@
|
|||
#[cfg(test)]
|
||||
use libc::c_char;
|
||||
|
||||
#[link(name = "kernaux")]
|
||||
extern "C" {
|
||||
#[cfg(test)]
|
||||
fn kernaux_utoa10(value: u64, buffer: *mut c_char);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use std::ffi::CStr;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = 2 + 2;
|
||||
assert_eq!(result, 4);
|
||||
fn utoa10() {
|
||||
let mut buffer: [i8; 1000] = [0; 1000];
|
||||
unsafe { kernaux_utoa10(123, buffer.as_mut_ptr()) };
|
||||
let result =
|
||||
unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
|
||||
assert_eq!(result, "123");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue