randomx_rust_wrapper/
lib.rs

1/*
2 * Copyright 2024 Fluence Labs Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#![warn(rust_2018_idioms)]
18#![warn(rust_2021_compatibility)]
19#![deny(
20    dead_code,
21    nonstandard_style,
22    unused_imports,
23    unused_mut,
24    unused_variables,
25    unused_unsafe,
26    unreachable_patterns
27)]
28
29pub mod bindings;
30pub mod cache;
31pub mod dataset;
32pub mod errors;
33pub mod flags;
34pub mod result_hash;
35#[cfg(test)]
36mod tests;
37pub mod vm;
38
39pub type RResult<T> = Result<T, errors::RandomXError>;
40
41pub use cache::Cache;
42pub use dataset::Dataset;
43pub use errors::RandomXError;
44pub use errors::VmCreationError;
45pub use flags::RandomXFlags;
46pub use result_hash::ResultHash;
47pub use vm::RandomXVM;
48
49macro_rules! try_alloc {
50    ($alloc:expr, $error:expr) => {{
51        let result = unsafe { $alloc };
52        if result.is_null() {
53            return Err($error)?;
54        }
55
56        result
57    }};
58}
59
60pub(crate) use try_alloc;