Rust: start writing binding

This commit is contained in:
Alex Kotov 2022-01-21 22:40:45 +05:00
parent ee21cb49b0
commit fec9f96ccc
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
3 changed files with 21 additions and 3 deletions

View File

@ -13,3 +13,4 @@ categories = ["api-bindings", "embedded", "external-ffi-bindings", "no-std", "pa
publish = true
[dependencies]
libc = "0.2.113"

1
pkgs/rust/rustfmt.toml Normal file
View File

@ -0,0 +1 @@
max_width = 80

View File

@ -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");
}
}