Skip to content

Commit

Permalink
Remove once_cell dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Sympatron committed Oct 2, 2024
1 parent f299d08 commit 2c0a336
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
4 changes: 1 addition & 3 deletions libosdp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ bitflags = "2.4.0"
embedded-io = { version = "0.6.1", features = ["alloc"] }
libosdp-sys = { path = "../libosdp-sys", default-features = false }
log = "0.4.20"
once_cell = { version = "1.18.0", optional = true, default-features = false, features = ["alloc", "critical-section"] }
serde = { version = "1.0.192", features = ["derive", "alloc"], default-features = false }
thiserror = { version = "1.0.50", optional = true }

Expand All @@ -30,8 +29,7 @@ sha256 = "1.5.0"

[features]
default = ["std"]
arc = ["once_cell"]
std = ["libosdp-sys/std", "thiserror", "serde/std", "once_cell/std", "arc"]
std = ["libosdp-sys/std", "thiserror", "serde/std"]

[[example]]
name = "cp"
Expand Down
30 changes: 8 additions & 22 deletions libosdp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,10 @@ pub use pdcap::*;
pub use pdid::*;
pub use pdinfo::*;

#[cfg(feature = "arc")]
use alloc::sync::Arc;
#[allow(unused_imports)]
use alloc::{
borrow::ToOwned, boxed::Box, ffi::CString, format, str::FromStr, string::String, vec, vec::Vec,
};
#[cfg(feature = "arc")]
use once_cell::sync::Lazy;
#[cfg(feature = "std")]
use thiserror::Error;

Expand Down Expand Up @@ -218,26 +214,16 @@ fn cstr_to_string(s: *const ::core::ffi::c_char) -> String {
s.to_str().unwrap().to_owned()
}

#[cfg(feature = "arc")]
static VERSION: Lazy<Arc<String>> = Lazy::new(|| {
let s = unsafe { libosdp_sys::osdp_get_version() };
Arc::new(cstr_to_string(s))
});

#[cfg(feature = "arc")]
static SOURCE_INFO: Lazy<Arc<String>> = Lazy::new(|| {
let s = unsafe { libosdp_sys::osdp_get_source_info() };
Arc::new(cstr_to_string(s))
});

/// Get LibOSDP version
#[cfg(feature = "arc")]
pub fn get_version() -> String {
VERSION.as_ref().clone()
pub fn get_version() -> &'static str {
let s = unsafe { libosdp_sys::osdp_get_version() };
let s = unsafe { core::ffi::CStr::from_ptr(s) };
s.to_str().unwrap()
}

/// Get LibOSDP source info string
#[cfg(feature = "arc")]
pub fn get_source_info() -> String {
SOURCE_INFO.as_ref().clone()
pub fn get_source_info() -> &'static str {
let s = unsafe { libosdp_sys::osdp_get_source_info() };
let s = unsafe { core::ffi::CStr::from_ptr(s) };
s.to_str().unwrap()
}

0 comments on commit 2c0a336

Please sign in to comment.