Comparator

A library to compare structs. BCS uses little-endian encoding for all integer types, so results might be unexpected.

Result

  struct Result has drop {
    inner: u8,
  }
  • inner - It will hold one of the following values: {SMALLER}, {EQUAL} or {GREATER}.

Interface

eq

It checks if the result of {compare} is EQUAL.

public fun eq(result: &Result): bool
  • @param result: This struct contains one of the following values: {SMALLER}, {EQUAL} or {GREATER}.

  • @return bool. True if it is EQUAL

lt

It checks if the result of {compare} is SMALLER.

public fun lt(result: &Result): bool
  • @param result: This struct contains one of the following values: {SMALLER}, {EQUAL} or {GREATER}.

  • @return bool. True if it is SMALLER

gt

It checks if the result of {compare} is GREATER.

public fun gt(result: &Result): bool
  • @param result: This struct contains one of the following values: {SMALLER}, {EQUAL} or {GREATER}.

  • @return bool. True if it is GREATER

lte

It checks if the result of {compare} is SMALLER or EQUAL.

public fun lte(result: &Result): bool
  • @param result: This struct contains one of the following values: {SMALLER}, {EQUAL} or {GREATER}.

  • @return bool. True if it is SMALLER or EQUAL.

gte

It checks if the result of {compare} is SMALLER or EQUAL.

public fun gte(result: &Result): bool
  • @param result: This struct contains one of the following values: {SMALLER}, {EQUAL} or {GREATER}.

  • @return bool. True if it is SMALLER or EQUAL.

compare

Compares two structs of type T. Performs a comparison of two types after BCS serialization.

public fun compare<T>(left: &T, right: &T): Result
  • @param left: A struct of type T.

  • @param right: A struct of type T.

  • @return Result. A struct that contains the following values: {SMALLER}, {EQUAL} or {GREATER}.

compare_u8_vector

Compares two bytes.

public fun compare_u8_vector(left: vector<u8>, right: vector<u8>): Result
  • @param left: A set of bytes.

  • @param right: A set of bytes.

  • @return Result. A struct that contains the following values: {SMALLER}, {EQUAL} or {GREATER}.

Last updated