pub trait TypeHash {
const HASH: Hash;
}
Expand description
Static type hash for a given type.
This trait allows you to determine the unique hash of any given type that
can be used in Rune through the HASH
associated constant.
This trait is usually implemented automatically through the Any
derive.
A type hash is unique for types which in Rune are considered the same. This
might not be true for types in Rust. For example, &str
and String
have
the same type hash:
use rune::TypeHash;
assert_eq!(<&str>::HASH, String::HASH);
Required Associated Constants§
Sourceconst HASH: Hash
const HASH: Hash
The complete type hash of the type including type parameters which uniquely identifiers a given type.
§Examples
use rune::TypeHash;
assert_ne!(String::HASH, i64::HASH);
fn is_a_string<T>() -> bool where T: TypeHash {
matches!(T::HASH, String::HASH)
}
assert!(is_a_string::<String>());
assert!(!is_a_string::<i64>());
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.