mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-02-27 22:13:12 -08:00
style(secret-memory): improve style in doc-tests around using the the ?-operator
This commit is contained in:
@@ -33,13 +33,10 @@ pub type MallocVec<T> = allocator_api2::vec::Vec<T, MallocAllocator>;
|
|||||||
/// # Example
|
/// # Example
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use rosenpass_secret_memory::alloc::memsec::malloc::{malloc_box_try, MallocBox};
|
/// # use rosenpass_secret_memory::alloc::memsec::malloc::{malloc_box_try, MallocBox};
|
||||||
/// # fn do_test() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
/// let data: u8 = 42;
|
/// let data: u8 = 42;
|
||||||
/// let malloc_box: MallocBox<u8> = malloc_box_try(data)?;
|
/// let malloc_box: MallocBox<u8> = malloc_box_try(data)?;
|
||||||
/// # assert_eq!(*malloc_box, 42u8);
|
/// # assert_eq!(*malloc_box, 42u8);
|
||||||
/// # Ok(())
|
/// # Ok::<(), anyhow::Error>(())
|
||||||
/// # }
|
|
||||||
/// # let _ = do_test();
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn malloc_box_try<T>(x: T) -> Result<MallocBox<T>, AllocError> {
|
pub fn malloc_box_try<T>(x: T) -> Result<MallocBox<T>, AllocError> {
|
||||||
MallocBox::<T>::try_new_in(x, MallocAllocator::new())
|
MallocBox::<T>::try_new_in(x, MallocAllocator::new())
|
||||||
|
|||||||
@@ -34,13 +34,10 @@ pub type MemfdSecVec<T> = allocator_api2::vec::Vec<T, MemfdSecAllocator>;
|
|||||||
/// # Example
|
/// # Example
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use rosenpass_secret_memory::alloc::memsec::memfdsec::{memfdsec_box_try, MemfdSecBox};
|
/// # use rosenpass_secret_memory::alloc::memsec::memfdsec::{memfdsec_box_try, MemfdSecBox};
|
||||||
/// # fn do_test() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
/// let data: u8 = 42;
|
/// let data: u8 = 42;
|
||||||
/// let memfdsec_box: MemfdSecBox<u8> = memfdsec_box_try(data)?;
|
/// let memfdsec_box: MemfdSecBox<u8> = memfdsec_box_try(data)?;
|
||||||
/// # assert_eq!(*memfdsec_box, 42u8);
|
/// # assert_eq!(*memfdsec_box, 42u8);
|
||||||
/// # Ok(())
|
/// # Ok::<(), anyhow::Error>(())
|
||||||
/// # }
|
|
||||||
/// # let _ = do_test();
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn memfdsec_box_try<T>(x: T) -> Result<MemfdSecBox<T>, AllocError> {
|
pub fn memfdsec_box_try<T>(x: T) -> Result<MemfdSecBox<T>, AllocError> {
|
||||||
MemfdSecBox::<T>::try_new_in(x, MemfdSecAllocator::new())
|
MemfdSecBox::<T>::try_new_in(x, MemfdSecAllocator::new())
|
||||||
|
|||||||
@@ -30,15 +30,13 @@ static ALLOC_TYPE: OnceLock<SecretAllocType> = OnceLock::new();
|
|||||||
/// # use std::alloc::Layout;
|
/// # use std::alloc::Layout;
|
||||||
/// # use allocator_api2::alloc::Allocator;
|
/// # use allocator_api2::alloc::Allocator;
|
||||||
/// # use rosenpass_secret_memory::alloc::{set_secret_alloc_type, SecretAlloc, SecretAllocType};
|
/// # use rosenpass_secret_memory::alloc::{set_secret_alloc_type, SecretAlloc, SecretAllocType};
|
||||||
/// # fn do_test () -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
/// set_secret_alloc_type(SecretAllocType::MemsecMalloc);
|
/// set_secret_alloc_type(SecretAllocType::MemsecMalloc);
|
||||||
/// let secret_alloc = SecretAlloc::default();
|
/// let secret_alloc = SecretAlloc::default();
|
||||||
/// unsafe {
|
/// unsafe {
|
||||||
/// let memory = secret_alloc.allocate(Layout::from_size_align_unchecked(42, 64))?;
|
/// let memory = secret_alloc.allocate(Layout::from_size_align_unchecked(128, 32))?;
|
||||||
/// }
|
/// }
|
||||||
/// # Ok(())
|
/// # Ok::<(), anyhow::Error>(())
|
||||||
/// # }
|
/// ```
|
||||||
/// # let _ = do_test();
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_secret_alloc_type(alloc_type: SecretAllocType) {
|
pub fn set_secret_alloc_type(alloc_type: SecretAllocType) {
|
||||||
ALLOC_TYPE.set(alloc_type).unwrap();
|
ALLOC_TYPE.set(alloc_type).unwrap();
|
||||||
@@ -128,15 +126,12 @@ pub type SecretVec<T> = allocator_api2::vec::Vec<T, SecretAlloc>;
|
|||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use rosenpass_secret_memory::alloc::{secret_box_try, SecretBox};
|
/// # use rosenpass_secret_memory::alloc::{secret_box_try, SecretBox};
|
||||||
/// # use rosenpass_secret_memory::alloc::SecretAllocType::MemsecMalloc;
|
/// # use rosenpass_secret_memory::alloc::SecretAllocType::MemsecMalloc;
|
||||||
/// # use rosenpass_secret_memory::alloc::set_secret_alloc_type;
|
/// use rosenpass_secret_memory::alloc::set_secret_alloc_type;
|
||||||
/// set_secret_alloc_type(MemsecMalloc);
|
/// set_secret_alloc_type(MemsecMalloc);
|
||||||
/// # fn do_test() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
/// let data: u8 = 42;
|
/// let data: u8 = 42;
|
||||||
/// let secret_box: SecretBox<u8> = secret_box_try(data)?;
|
/// let secret_box: SecretBox<u8> = secret_box_try(data)?;
|
||||||
/// # assert_eq!(*secret_box, 42u8);
|
/// # assert_eq!(*secret_box, 42u8);
|
||||||
/// # Ok(())
|
/// # Ok::<(), anyhow::Error>(())
|
||||||
/// # }
|
|
||||||
/// # let _ = do_test();
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn secret_box_try<T>(x: T) -> Result<SecretBox<T>, AllocError> {
|
pub fn secret_box_try<T>(x: T) -> Result<SecretBox<T>, AllocError> {
|
||||||
SecretBox::<T>::try_new_in(x, SecretAlloc::default())
|
SecretBox::<T>::try_new_in(x, SecretAlloc::default())
|
||||||
|
|||||||
Reference in New Issue
Block a user