pers 0.1.0

Parser for Windows Portable Executable (PE) files that borrows the file data, a Rust port of PeNet
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! A write once cell for cached parse results: thread safe with `std`, single threaded without.
#![cfg(any(feature = "dotnet", feature = "authenticode"))]

#[cfg(feature = "std")]
pub(crate) type Lazy<T> = std::sync::OnceLock<T>;

#[cfg(not(feature = "std"))]
pub(crate) type Lazy<T> = core::cell::OnceCell<T>;

/// Get the cached result or compute it. Errors are cached too and cloned on every access.
pub(crate) fn cached<T>(
    cell: &Lazy<crate::Result<T>>,
    init: impl FnOnce() -> crate::Result<T>,
) -> crate::Result<&T> {
    cell.get_or_init(init).as_ref().map_err(Clone::clone)
}