Skip to content

Commit

Permalink
fix with_params
Browse files Browse the repository at this point in the history
  • Loading branch information
reiase committed Jun 23, 2024
1 parent a6e32fb commit 374f10e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hyperparameter"
version = "0.5.10"
version = "0.5.11"
license = "Apache-2.0"
description = "A high performance configuration system for Rust."
homepage = "https://reiase.github.io/hyperparameter/"
Expand Down
17 changes: 10 additions & 7 deletions core/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::collections::HashSet;
use std::fmt::Debug;

use const_str;
use xxhash_rust;

use crate::storage::{
frozen_global_storage, Entry, GetOrElse, MultipleVersion, Params, THREAD_STORAGE,
};
Expand Down Expand Up @@ -184,15 +187,15 @@ pub fn frozen() {
#[macro_export]
macro_rules! get_param {
($name:expr, $default:expr) => {{
const CONST_KEY: &str = ::const_str::replace!(stringify!($name), ";", "");
const CONST_HASH: u64 = ::xxhash_rust::const_xxh64::xxh64(CONST_KEY.as_bytes(), 42);
const CONST_KEY: &str = const_str::replace!(stringify!($name), ";", "");
const CONST_HASH: u64 = xxhash_rust::const_xxh64::xxh64(CONST_KEY.as_bytes(), 42);
THREAD_STORAGE.with(|ts| ts.borrow_mut().get_or_else(CONST_HASH, $default))
// ParamScope::default().get_or_else(CONST_HASH, $default)
}};

($name:expr, $default:expr, $help: expr) => {{
const CONST_KEY: &str = ::const_str::replace!(stringify!($name), ";", "");
const CONST_HASH: u64 = ::xxhash_rust::const_xxh64::xxh64(CONST_KEY.as_bytes(), 42);
const CONST_KEY: &str = const_str::replace!(stringify!($name), ";", "");
const CONST_HASH: u64 = xxhash_rust::const_xxh64::xxh64(CONST_KEY.as_bytes(), 42);
// ParamScope::default().get_or_else(CONST_HASH, $default)
{
const CONST_HELP: &str = $help;
Expand Down Expand Up @@ -238,7 +241,7 @@ macro_rules! with_params {
) =>{
let mut ps = ParamScope::default();
{
const CONST_KEY: &str = ::const_str::replace!(stringify!($($key).+), ";", "");
const CONST_KEY: &str = const_str::replace!(stringify!($($key).+), ";", "");
ps.put(CONST_KEY, $val);
}
with_params!(params ps; $($body)*)
Expand All @@ -251,7 +254,7 @@ macro_rules! with_params {
$($body:tt)*
) => {
{
const CONST_KEY: &str = ::const_str::replace!(stringify!($($key).+), ";", "");
const CONST_KEY: &str = const_str::replace!(stringify!($($key).+), ";", "");
$ps.put(CONST_KEY, $val);
}
with_params!(params $ps; $($body)*)
Expand Down Expand Up @@ -339,7 +342,7 @@ macro_rules! with_params_readonly {
) =>{
let mut ps = ParamScope::default();
{
const CONST_KEY: &str = ::const_str::replace!(stringify!($($key).+), ";", "");
const CONST_KEY: &str = const_str::replace!(stringify!($($key).+), ";", "");
ps.put(CONST_KEY, $val);
}
with_params!(params ps; $($body)*)
Expand Down
2 changes: 2 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub use crate::storage::THREAD_STORAGE;
pub use crate::value::Value;
pub use crate::xxh::xxhash;
pub use crate::xxh::XXHashable;
pub use const_str;
pub use xxhash_rust;

#[cfg(feature = "clap")]
mod cli;
Expand Down

0 comments on commit 374f10e

Please sign in to comment.