pub struct ClassHash(/* private fields */);Expand description
A type-safe wrapper for Starknet class hashes.
Class hashes are 256-bit values represented as hexadecimal strings prefixed with “0x”. This type ensures that only valid class hashes can be constructed and used throughout the application.
§Format Requirements
- Must start with “0x”
- Must contain only hexadecimal characters (0-9, a-f, A-F)
- Must be at most 66 characters long (including “0x” prefix)
§Examples
use verifier::class_hash::ClassHash;
// Valid class hash
let hash = ClassHash::new("0x044dc2b3239382230d8b1e943df23b96f52eebcac93efe6e8bde92f9a2f1da18")?;
println!("Hash: {}", hash);
// Shorter hashes are also valid
let short_hash = ClassHash::new("0x123")?;
println!("Short hash: {}", short_hash);
// Invalid hashes will return an error
assert!(ClassHash::new("invalid").is_err());
assert!(ClassHash::new("0xGGG").is_err());Implementations§
Source§impl ClassHash
impl ClassHash
Sourcepub fn new(raw: &str) -> Result<Self, ClassHashError>
pub fn new(raw: &str) -> Result<Self, ClassHashError>
Creates a new ClassHash from a string.
Validates that the input string follows the correct format for a Starknet class hash:
- Must start with “0x”
- Must contain only hexadecimal characters (0-9, a-f, A-F)
- Must be at most 66 characters long (including “0x” prefix)
§Arguments
raw- The string representation of the class hash
§Returns
Returns Ok(ClassHash) if the input is valid, or Err(ClassHashError) with
detailed error information if the input is invalid.
§Examples
use verifier::class_hash::ClassHash;
// Valid class hash
let hash = ClassHash::new("0x044dc2b3239382230d8b1e943df23b96f52eebcac93efe6e8bde92f9a2f1da18")?;
println!("Created hash: {}", hash);
// Invalid format will return an error
let result = ClassHash::new("invalid_hash");
assert!(result.is_err());§Errors
Returns ClassHashError::Match if the input doesn’t match the expected format,
or ClassHashError::RegexError if there’s an internal regex compilation error.
Trait Implementations§
Source§impl Ord for ClassHash
impl Ord for ClassHash
Source§impl PartialOrd for ClassHash
impl PartialOrd for ClassHash
impl Eq for ClassHash
impl StructuralPartialEq for ClassHash
Auto Trait Implementations§
impl Freeze for ClassHash
impl RefUnwindSafe for ClassHash
impl Send for ClassHash
impl Sync for ClassHash
impl Unpin for ClassHash
impl UnwindSafe for ClassHash
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.