From a9275430f21578945c84fe51e1bb16c316c3228f Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Mon, 31 Jan 2022 09:43:27 +0500 Subject: [PATCH] Rust: Import unsafe funcs --- pkgs/rust/kernaux/src/lib.rs | 2 ++ pkgs/rust/kernaux/src/ntoa.rs | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 pkgs/rust/kernaux/src/ntoa.rs diff --git a/pkgs/rust/kernaux/src/lib.rs b/pkgs/rust/kernaux/src/lib.rs index 8b13789..8815ac7 100644 --- a/pkgs/rust/kernaux/src/lib.rs +++ b/pkgs/rust/kernaux/src/lib.rs @@ -1 +1,3 @@ +mod ntoa; +pub use ntoa::*; diff --git a/pkgs/rust/kernaux/src/ntoa.rs b/pkgs/rust/kernaux/src/ntoa.rs new file mode 100644 index 0000000..dedafe9 --- /dev/null +++ b/pkgs/rust/kernaux/src/ntoa.rs @@ -0,0 +1,15 @@ +#[cfg(test)] +mod tests { + use std::ffi::CStr; + + use kernaux_sys::{utoa10, UTOA10_BUFFER_SIZE}; + + #[test] + fn test_utoa10() { + let mut buffer: [i8; UTOA10_BUFFER_SIZE] = [0; UTOA10_BUFFER_SIZE]; + unsafe { utoa10(123, buffer.as_mut_ptr()) }; + let result = + unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap(); + assert_eq!(result, "123"); + } +}