mirror of
https://github.com/tailix/libkernaux.git
synced 2024-11-13 11:04:27 -05:00
Rust: implement ntoa::utoa10
This commit is contained in:
parent
7abc9d6d4f
commit
29e0cd73f9
2 changed files with 21 additions and 13 deletions
|
@ -1,3 +1,13 @@
|
|||
mod ntoa;
|
||||
|
||||
pub use ntoa::*;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_ntoa() {
|
||||
assert_eq!(utoa10(123), "123");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
pub use kernaux_sys::{
|
||||
ITOA10_BUFFER_SIZE, ITOA16_BUFFER_SIZE, ITOA_BUFFER_SIZE,
|
||||
UTOA10_BUFFER_SIZE, UTOA16_BUFFER_SIZE, UTOA_BUFFER_SIZE,
|
||||
};
|
||||
use std::ffi::CStr;
|
||||
|
||||
use kernaux_sys::{utoa10 as kernaux_utoa10, UTOA10_BUFFER_SIZE};
|
||||
|
||||
pub fn utoa10(value: u64) -> String {
|
||||
let mut buffer: [i8; UTOA10_BUFFER_SIZE] = [0; UTOA10_BUFFER_SIZE];
|
||||
unsafe { kernaux_utoa10(value, buffer.as_mut_ptr()) };
|
||||
let result = unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
|
||||
String::from(result)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use std::ffi::CStr;
|
||||
|
||||
use kernaux_sys::utoa10;
|
||||
|
||||
#[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");
|
||||
assert_eq!(utoa10(123), "123");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue