pub struct Hash;
Expand description
This class contains some tools for hashing data within StereoKit! Certain systems in StereoKit use string hashes instead of full strings for faster search and compare, like UI and Materials, so this class gives access to the code SK uses for hashing. StereoKit currently internally uses a 64 bit FNV hash, though this detail should be pretty transparent to developers
Implementations§
Source§impl Hash
impl Hash
Sourcepub fn string(str: impl AsRef<str>) -> IdHashT
pub fn string(str: impl AsRef<str>) -> IdHashT
This will hash the UTF8 representation of the given string into a hash value that StereoKit can use. https://stereokit.net/Pages/StereoKit/Hash/String.html
str
- A string (UTF8),that will be hashed.
Returns a StereoKit hash representing the provided string.
see also hash_string
Hash::string_with
§Examples
use stereokit_rust::util::Hash;
let hash = Hash::string("Hello World");
assert_eq!(hash, 4420528118743043111);
Sourcepub fn string_with(str: impl AsRef<str>, root: IdHashT) -> IdHashT
pub fn string_with(str: impl AsRef<str>, root: IdHashT) -> IdHashT
This will hash the UTF8 representation of the given string into a hash value that StereoKit can use. This overload allows you to combine your hash with an existing hash. https://stereokit.net/Pages/StereoKit/Hash/String.html
str
- A string (UTF8),that will be hashed.root
- The hash value this new hash will start from.
Returns a StereoKit hash representing a combination of the provided string and the root hash.
see also hash_string_with
Hash::string
§Examples
use stereokit_rust::util::Hash;
let hash1 = Hash::string("Hello");
assert_eq!(hash1, 7201466553693376363);
let hash2 = Hash::string_with(" World", hash1);
assert_eq!(hash2, 4420528118743043111);
Sourcepub fn int(val: i32) -> IdHashT
pub fn int(val: i32) -> IdHashT
This will hash an integer into a hash value that StereoKit can use. This is helpful for adding in some uniqueness using something like a for loop index. This may be best when combined with additional hashes. https://stereokit.net/Pages/StereoKit/Hash/Int.html
val
- An integer that will be hashed.
Returns a StereoKit hash representing the provided integer.
see also hash_int
Hash::int_with
§Examples
use stereokit_rust::util::Hash;
let hash = Hash::int(123456789);
assert_eq!(hash, 8379007418144316681);
Sourcepub fn int_with(int: i32, root: IdHashT) -> IdHashT
pub fn int_with(int: i32, root: IdHashT) -> IdHashT
This will hash an integer into a hash value that StereoKit can use. This is helpful for adding in some uniqueness using something like a for loop index. This overload allows you to combine your hash with an existing hash. https://stereokit.net/Pages/StereoKit/Hash/Int.html
val
- An integer that will be hashed.root
- The hash value this new hash will start from.
Returns a StereoKit hash representing a combination of the provided string and the root hash.
see also hash_int_with
Hash::int
§Examples
use stereokit_rust::util::Hash;
let hash1 = Hash::int(123456789);
assert_eq!(hash1, 8379007418144316681);
let hash2 = Hash::int_with(123456789, hash1);
assert_eq!(hash2, 13864748593440029765);
Auto Trait Implementations§
impl Freeze for Hash
impl RefUnwindSafe for Hash
impl Send for Hash
impl Sync for Hash
impl Unpin for Hash
impl UnwindSafe for Hash
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.