rhai/build.template

60 lines
2.0 KiB
Plaintext
Raw Normal View History

#[cfg(feature = "stable_hash")]
use core::cell::OnceCell;
2022-10-15 06:04:14 +02:00
// [236,800,954,213], haha funny yume nikki reference
#[cfg(not(feature = "stable_hash"))]
/// Fixed hashing seeds for stable hashing.
///
/// Set to [`None`] to disable stable hashing.
///
/// See [`set_rhai_ahash_seed`] for more.
///
/// You can also set this at compile time by disabling `stable_hash` and setting the `RHAI_AHASH_SEED`
/// environment variable instead.
///
/// E.g. `env RHAI_AHASH_SEED ="[236,800,954,213]"`
const AHASH_SEED: Option<[u64; 4]> = {{AHASH_SEED}};
#[cfg(feature = "stable_hash")]
2022-10-15 06:04:14 +02:00
/// Fixed hashing seeds for stable hashing.
///
2022-10-15 06:04:14 +02:00
/// Set to [`None`] to disable stable hashing.
///
/// See [`set_rhai_ahash_seed`] for more.
///
/// You can also set this at compile time by disabling `stable_hash` and setting the `RHAI_AHASH_SEED`
/// environment variable instead.
///
/// E.g. `env RHAI_AHASH_SEED ="[236,800,954,213]"`
static AHASH_SEED: OnceCell<Option<[u64; 4]>> = OnceCell::new();
#[cfg(feature = "stable_hash")]
#[doc(cfg(feature = "stable_hash"))]
/// Sets the Rhai Ahash seed. This is used to hash functions and the like.
///
/// This is a global variable, and thus will affect every Rhai instance.
/// This should not be used _unless_ you know you need it.
///
/// **WARNING**:
/// - You can only call this function **ONCE** for the whole of your program execution.
/// - You should gracefully handle the `Err(())`.
/// - You **MUST** call this before **ANY** Rhai operation occurs (e.g. creating an [`Engine`]).
pub fn set_rhai_ahash_seed(new_seed: Option<[u64; 4]>) -> Result<(), Option<[u64; 4]>> {
AHASH_SEED.set(new_seed)
}
#[cfg(feature = "stable_hash")]
/// Gets the current Rhai Ahash Seed.
///
/// See [`set_rhai_ahash_seed`] for more.
pub fn get_rhai_ahash_seed() -> Option<[u64; 4]> {
AHASH_SEED.get().map(|x| *x).flatten()
}
#[cfg(not(feature = "stable_hash"))]
/// Gets the current Rhai Ahash Seed.
///
/// See [`AHASH_SEED`] and [`set_rhai_ahash_seed`] for more.
pub fn get_rhai_ahash_seed() -> Option<[u64; 4]> {
AHASH_SEED
}