Skip to content

Commit

Permalink
Tweak custom signature
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Oct 7, 2024
1 parent 966364d commit 8d83265
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
10 changes: 3 additions & 7 deletions src/custom.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
//! An implementation which calls out to an externally defined function.
use crate::Error;
use core::{mem::MaybeUninit, num::NonZeroU32};
use core::mem::MaybeUninit;

pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
extern "Rust" {
fn __getrandom_custom(dest: *mut u8, len: usize) -> u32;
}
let ret = unsafe { __getrandom_custom(dest.as_mut_ptr().cast(), dest.len()) };
match NonZeroU32::new(ret) {
None => Ok(()),
Some(code) => Err(Error::from(code)),
fn __getrandom_custom(dest: *mut u8, len: usize) -> Result<(), Error>;
}
unsafe { __getrandom_custom(dest.as_mut_ptr().cast(), dest.len()) }
}
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
//!
//! ```
//! #[no_mangle]
//! unsafe fn __getrandom_custom(dest: *mut u8, len: usize) -> u32 {
//! unsafe fn __getrandom_custom(dest: *mut u8, len: usize) -> Result<(), getrandom::Error> {
//! todo!()
//! }
//! ```
Expand All @@ -127,8 +127,8 @@
//! use the following custom backend which always returns "unsupported" error:
//! ```
//! #[no_mangle]
//! unsafe fn __getrandom_custom(dest: *mut u8, len: usize) -> u32 {
//! getrandom::Error::UNSUPPORTED.code().get()
//! unsafe fn __getrandom_custom(dest: *mut u8, len: usize) -> Result<(), getrandom::Error> {
//! Err(getrandom::Error::UNSUPPORTED)
//! }
//! ```
//!
Expand Down

0 comments on commit 8d83265

Please sign in to comment.