Skip to content

Commit

Permalink
feat: Make time module in lib_ccxr/util & Add helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
IshanGrover2004 committed Jul 16, 2024
1 parent 8a74b19 commit 2780a65
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/rust/lib_ccxr/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,17 @@
pub mod bits;
pub mod levenshtein;
pub mod log;
pub mod time;

use std::os::raw::c_char;

/// Helper function that converts a Rust-String (`string`) to C-String (`buffer`).
///
/// # Safety
///
/// `buffer` must have enough allocated space for `string` to fit.
pub fn write_string_into_pointer(buffer: *mut c_char, string: &str) {
let buffer = unsafe { std::slice::from_raw_parts_mut(buffer as *mut u8, string.len() + 1) };
buffer[..string.len()].copy_from_slice(string.as_bytes());
buffer[string.len()] = b'\0';
}

0 comments on commit 2780a65

Please sign in to comment.