Skip to content

Commit be09e24

Browse files
committed
Replace once_cell with the now-standard LazyLock
As pointed out by code scan [intel#88], `std::sync::LazyLock` is the standard way to initialize static values. `LazyLock` has been available since Rust [v1.80.0]. This change switches to `LazyLock` and removes the now-unnecessary `once_cell` crate. It also throws a few `rust-version` annotations in to remind users what version of Rust to use. [intel#88]: https://github.com/intel/openvino-rs/security/code-scanning/88 [v1.80.0]: https://releases.rs/docs/1.80.0
1 parent 8df64e5 commit be09e24

File tree

5 files changed

+7
-13
lines changed

5 files changed

+7
-13
lines changed

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ authors = ["OpenVINO Project Developers"]
1313
edition = "2021"
1414
license = "Apache-2.0"
1515
repository = "https://github.com/intel/openvino-rs"
16+
# This is only necessary for use of `LazyLock` in `openvino-sys`.
17+
rust-version = "1.80.0"
1618

1719
[workspace.dependencies]
1820
openvino-sys = { path = "crates/openvino-sys", version = "=0.8.0" }

crates/openvino-sys/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ authors.workspace = true
66
license.workspace = true
77
edition.workspace = true
88
repository.workspace = true
9+
rust-version.workspace = true
910
readme = "README.md"
1011
documentation = "https://docs.rs/openvino-sys"
1112
keywords = ["openvino", "machine-learning", "ml", "neural-network"]
@@ -25,7 +26,6 @@ include = [
2526
links = "openvino_c_api"
2627

2728
[dependencies]
28-
once_cell = { version = "1.20", optional = true }
2929
libloading = { version = "0.8", optional = true }
3030
openvino-finder = { workspace = true }
3131

@@ -38,7 +38,7 @@ env_logger = { workspace = true }
3838
# - Will find and bind to an OpenVINO shared library at compile time.
3939
dynamic-linking = []
4040
# - Will bind to an OpenVINO shared library at runtime using `load`.
41-
runtime-linking = ["libloading", "once_cell"]
41+
runtime-linking = ["libloading"]
4242

4343
[package.metadata.docs.rs]
4444
features = ["runtime-linking"]

crates/openvino-sys/src/linking/runtime.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ macro_rules! link {
1010
}
1111
)+
1212
) => (
13-
use once_cell::sync::Lazy;
1413
use libloading;
1514
use std::path::PathBuf;
16-
use std::sync::Arc;
17-
use std::sync::RwLock;
15+
use std::sync::{Arc, LazyLock, RwLock};
1816

1917
// Wrap the loaded functions.
2018
#[derive(Debug)]
@@ -34,7 +32,7 @@ macro_rules! link {
3432
}
3533

3634
// `LIBRARY` holds the shared library reference.
37-
static LIBRARY: Lazy<RwLock<Option<Arc<SharedLibrary>>>> = Lazy::new(|| RwLock::new(None));
35+
static LIBRARY: LazyLock<RwLock<Option<Arc<SharedLibrary>>>> = LazyLock::new(|| RwLock::new(None));
3836

3937
// Helper function for accessing the thread-local version of the library.
4038
fn with_library<T, F>(f: F) -> Option<T>

crates/openvino/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ authors.workspace = true
66
license.workspace = true
77
edition.workspace = true
88
repository.workspace = true
9+
rust-version.workspace = true
910
readme = "README.md"
1011
documentation = "https://docs.rs/openvino"
1112
keywords = ["openvino", "machine-learning", "ml", "neural-network"]

0 commit comments

Comments
 (0)