Module hsh::macros

source ·
Expand description

The macros module contains functions for generating macros.

Macros for the hsh crate.

This module contains macros that simplify working with Hash structs.

These macros can greatly simplify code that uses the Hash struct, making it easier to read and maintain.

Generic macros for the hsh crate.

This crate provides the following macros:

MacroDescription
hshCalls the parse method on the Hash struct from the hsh crate.
hsh_assertAsserts that a given condition is true. If the condition is false, the macro will cause the program to panic with the message “Assertion failed!”.
hsh_containsChecks if a given string contains a specified substring.
hsh_in_rangeChecks if a given value is within a specified range (inclusive).
hsh_joinJoins multiple strings together using a specified separator.
hsh_maxReturns the maximum value from a set of given values.
hsh_minReturns the minimum value from a set of given values.
hsh_printPrints the given arguments to the console, similar to the println! macro.
hsh_print_vecPrints the elements of a given vector to the console, each on a new line.
hsh_splitSplits a given string into a vector of words, dividing at each occurrence of whitespace.
hsh_vecCreates a new vector containing the given elements.
hsh_parseAttempts to parse a given input into a u64 value, returning a Result.

HSH Macros

The library also provides several macros for common operations on the Hash struct:

  • to_str_error: Abstracts away the error handling for the to_string method.
  • random_string: Generates a random string of a specified length, consisting of alphanumeric characters.
  • match_algo: Matches given hash algorithm strings to their corresponding enum variants.
  • generate_hash: Generates a new hash for a given password, salt, and algorithm.
  • new_hash: Creates a new instance of the Hash struct with a given password, salt, and algorithm.
  • hash_length: Returns the length of the hash for a given Hash struct instance.