pub struct Hash(/* private fields */);Expand description
The primitive hash that among other things is used to reference items, types, and native functions.
§Examples
use rune::Hash;
assert_ne!(Hash::index(0), Hash::index(1));Implementations§
Source§impl Hash
impl Hash
Sourcepub const EMPTY: Self
pub const EMPTY: Self
The empty hash.
§Examples
use rune::Hash;
assert_ne!(Hash::index(0), Hash::EMPTY);
assert!(Hash::EMPTY.as_non_empty().is_none());Sourcepub fn as_non_empty(&self) -> Option<NonZeroHash>
pub fn as_non_empty(&self) -> Option<NonZeroHash>
Return the current hash if it is non-empty.
§Examples
use rune::Hash;
assert!(Hash::index(0).as_non_empty().is_some());
assert!(Hash::EMPTY.as_non_empty().is_none());Sourcepub fn index(index: usize) -> Self
pub fn index(index: usize) -> Self
Construct a hash from an index.
§Examples
use rune::Hash;
assert_ne!(Hash::index(0), Hash::index(1));Sourcepub fn ident(name: &str) -> Hash
pub fn ident(name: &str) -> Hash
Get the hash corresponding to a string identifier like function or
hello_world.
§Examples
use rune::Hash;
assert_ne!(Hash::ident("foo"), Hash::index(0));Sourcepub fn type_hash(path: impl ToTypeHash) -> Self
pub fn type_hash(path: impl ToTypeHash) -> Self
Get the hash of a type.
§Examples
use rune::Hash;
assert!(!Hash::type_hash(["main"]).is_empty());
assert!(!Hash::type_hash(["main", "other"]).is_empty());Sourcepub fn associated_function(
type_hash: impl IntoHash,
name: impl IntoHash,
) -> Self
pub fn associated_function( type_hash: impl IntoHash, name: impl IntoHash, ) -> Self
Construct a hash to an instance function, where the instance is a pre-determined type.
§Examples
use rune::Hash;
use rune::runtime::Protocol;
assert!(!Hash::associated_function("main", &Protocol::INTO_TYPE_NAME).is_empty());Sourcepub fn field_function(
protocol: impl IntoHash,
type_hash: Hash,
name: impl IntoHash,
) -> Self
pub fn field_function( protocol: impl IntoHash, type_hash: Hash, name: impl IntoHash, ) -> Self
Construct a hash corresponding to a field function.
§Examples
use rune::{Hash, TypeHash};
use rune::runtime::Protocol;
assert!(!Hash::field_function(&Protocol::ADD, i64::HASH, "field").is_empty());Sourcepub fn index_function(
protocol: impl IntoHash,
type_hash: Hash,
index: Hash,
) -> Self
pub fn index_function( protocol: impl IntoHash, type_hash: Hash, index: Hash, ) -> Self
Construct an index function.
§Examples
use rune::{Hash, TypeHash};
use rune::runtime::Protocol;
assert!(!Hash::index_function(&Protocol::ADD, i64::HASH, Hash::index(1)).is_empty());Sourcepub fn static_bytes(bytes: &[u8]) -> Hash
pub fn static_bytes(bytes: &[u8]) -> Hash
Get the hash corresponding to a static byte array.
Sourcepub fn object_keys<I>(keys: I) -> Self
pub fn object_keys<I>(keys: I) -> Self
Hash the given iterator of object keys.
Sourcepub const fn with_generics(self, generics: Self) -> Self
pub const fn with_generics(self, generics: Self) -> Self
Mix in generics hash.
The generics hash must be a combination of the output from
with_type_parameters and with_function_parameters.
Sourcepub const fn with_type_parameters(self, ty: Self) -> Self
pub const fn with_type_parameters(self, ty: Self) -> Self
Mix the current hash with type parameters.
Sourcepub const fn with_function_parameters(self, f: Self) -> Self
pub const fn with_function_parameters(self, f: Self) -> Self
Mix the current hash with function parameters.
Sourcepub const fn parameters<const N: usize>(params: [Hash; N]) -> Self
pub const fn parameters<const N: usize>(params: [Hash; N]) -> Self
Hash type parameters.
Trait Implementations§
Source§impl<'__de, __A> Decode<'__de, Binary, __A> for Hashwhere
__A: Allocator,
impl<'__de, __A> Decode<'__de, Binary, __A> for Hashwhere
__A: Allocator,
Source§const IS_BITWISE_DECODE: bool = false
const IS_BITWISE_DECODE: bool = false
Source§impl<'__de, __A> Decode<'__de, Text, __A> for Hashwhere
__A: Allocator,
impl<'__de, __A> Decode<'__de, Text, __A> for Hashwhere
__A: Allocator,
Source§const IS_BITWISE_DECODE: bool = false
const IS_BITWISE_DECODE: bool = false
Source§impl<'de> Deserialize<'de> for Hash
impl<'de> Deserialize<'de> for Hash
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Encode<Binary> for Hash
impl Encode<Binary> for Hash
Source§const IS_BITWISE_ENCODE: bool = false
const IS_BITWISE_ENCODE: bool = false
Source§impl Encode<Text> for Hash
impl Encode<Text> for Hash
Source§const IS_BITWISE_ENCODE: bool = false
const IS_BITWISE_ENCODE: bool = false
Source§impl Ord for Hash
impl Ord for Hash
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq<Hash> for NonZeroHash
impl PartialEq<Hash> for NonZeroHash
Source§impl PartialEq<NonZeroHash> for Hash
impl PartialEq<NonZeroHash> for Hash
Source§fn eq(&self, other: &NonZeroHash) -> bool
fn eq(&self, other: &NonZeroHash) -> bool
self and other values to be equal, and is used by ==.