corelib_imports
Fully qualified path: corelib_imports
Modules
| array | — |
| integer | — |
| keccak | — |
| bounded_int | — |
| circuit | — |
Modules
Modules
| array | — |
| integer | — |
| keccak | — |
| bounded_int | — |
| circuit | — |
array
Fully qualified path: corelib_imports::array
Re-exports:
integer
Fully qualified path: corelib_imports::integer
Re-exports:
keccak
Fully qualified path: corelib_imports::keccak
Re-exports:
| cairo_keccak | Computes the Keccak-256 hash of a byte sequence with custom padding. This function allows hashing arbitrary byte sequences by providing the input as… |
| keccak_add_u256_be | — |
bounded_int
Fully qualified path: corelib_imports::bounded_int
Re-exports:
| AddHelper | A helper trait for adding two BoundedInt instances. |
| DivRemHelper | A helper trait for dividing two BoundedInt instances. |
| MulHelper | A helper trait for multiplying two BoundedInt instances. |
| bounded_int_div_rem | — |
| downcast | Downcasts FromType to ToType - for types where conversion may fail. If done for wrong types would cause a compiler panic at the Sierra stage. |
| upcast | Upcasts FromType to ToType - for types where conversion is always legal. If done for wrong types would cause a compiler panic at the Sierra stage. |
circuit
Fully qualified path: corelib_imports::circuit
Modules
Re-exports:
| u384 | A 384-bit unsigned integer, used for circuit values. |
| AddInputResult | The result of filling an input in the circuit instance’s data. This enum represents the state of input filling process, indicating whether all inputs have been provided or more are needed. |
| u96 | A 96-bit unsigned integer type used as the basic building block for multi-limb arithmetic. |
| CircuitDefinition | A trait for defining a circuit’s structure and behavior. This trait is used to define the structure of a circuit, including its inputs,… |
| IntoCircuitInputValue | Trait for converting a value to a circuit input value. |
| CircuitData | A type representing a circuit instance data with all the inputs added. |
| CircuitInputAccumulator | Type for accumulating inputs into the circuit instance’s data. |
| U96Guarantee | A value that is guaranteed to fit in a u96. The destructor of the type verifies that the value is indeed within the range of a u96. |
| add_circuit_input | Fill an input in the circuit instance’s data. |
| init_circuit_data | Initializes the input data for running an instance of the circuit. |
| into_u96_guarantee | Converts ‘T’ into a ‘U96Guarantee’. ‘T’ must be a value that fits inside a u96, for example: u8, u96 or BoundedInt < 0, 12>. |
Modules
Modules
conversions
Fully qualified path: corelib_imports::circuit::conversions
Re-exports:
| NZ_POW32_TYPED | — |
| NZ_POW64_TYPED | — |
| NZ_POW96_TYPED | — |
| POW32 | — |
| POW32_TYPED | — |
| POW64 | — |
| POW64_TYPED | — |
| POW96_TYPED | — |
| AddHelperTo128By64Impl | — |
| AddHelperTo128By96Impl | — |
| AddHelperTo96By32Impl | — |
| DivRemU128By64 | — |
| DivRemU128By96 | — |
| DivRemU96By32 | — |
| DivRemU96By64 | — |
| MulHelper32By96Impl | — |
| MulHelper64By32Impl | — |
| MulHelper64By64Impl | — |
| upcast | Upcasts FromType to ToType - for types where conversion is always legal. If done for wrong types would cause a compiler panic at the Sierra stage. |
core
Main entrypoint for the Cairo core library.
Fully qualified path: core
Modules
| circuit | Efficient modular arithmetic computations using arithmetic circuits. This module provides a type-safe way to perform modular arithmetic operations using… |
| keccak | Keccak-256 cryptographic hash function implementation…. |
| integer | Integer types and operations. This module provides the built-in integer types and their associated operations…. |
| internal | — |
| array | A contiguous collection of elements of the same type in memory, written Array<T> . Arrays have _ O _ (1) indexing, _ O _ (1) push and _ O _ (1) pop (from the front)…. |
Modules
Modules
| circuit | Efficient modular arithmetic computations using arithmetic circuits. This module provides a type-safe way to perform modular arithmetic operations using… |
| keccak | Keccak-256 cryptographic hash function implementation…. |
| integer | Integer types and operations. This module provides the built-in integer types and their associated operations…. |
| internal | — |
| array | A contiguous collection of elements of the same type in memory, written Array<T> . Arrays have _ O _ (1) indexing, _ O _ (1) push and _ O _ (1) pop (from the front)…. |
circuit
Efficient modular arithmetic computations using arithmetic circuits.
This module provides a type-safe way to perform modular arithmetic operations using arithmetic circuits. It is particularly useful for implementing cryptographic algorithms and other computations that require efficient modular arithmetic with large numbers.
Core Features
- Modular arithmetic operations (add, subtract, multiply, inverse)
- Support for numbers up to 384 bits
- Type-safe circuit construction
- Efficient evaluation of complex expressions
Examples
Basic Arithmetic
Here’s an example showing basic modular arithmetic operations:
use core::circuit::{
CircuitElement, EvalCircuitTrait, CircuitOutputsTrait, CircuitInput, CircuitModulus,
AddInputResultTrait, CircuitInputs, circuit_add, circuit_mul,
};
// Compute (a + b) * c mod p
let a = CircuitElement::<CircuitInput<0>> {};
let b = CircuitElement::<CircuitInput<1>> {};
let c = CircuitElement::<CircuitInput<2>> {};
let sum = circuit_add(a, b);
let result = circuit_mul(sum, c);
// Evaluate with inputs [3, 6, 2] modulo 7
let modulus = TryInto::<_, CircuitModulus>::try_into([7, 0, 0, 0]).unwrap();
let outputs = (result,)
.new_inputs()
.next([3, 0, 0, 0])
.next([6, 0, 0, 0])
.next([2, 0, 0, 0])
.done()
.eval(modulus)
.unwrap();
// Result: (3 + 6) * 2 mod 7 = 4
assert!(outputs.get_output(result) == 4.into());
How It Works
The module uses a type-based approach to construct and evaluate arithmetic circuits:
- Circuit elements are created using
CircuitElement<T>where T defines their role (input or gate) - Basic operations combine elements into more complex expressions (chaining gates to create a circuit)
- The final circuit is evaluated with specific input values and a modulus
Operations are performed using a multi-limb representation for large numbers, with each number represented as four 96-bit limbs allowing for values up to 384 bits.
Performance Considerations
- Circuit evaluation is optimized for large modular arithmetic operations
- The multi-limb representation allows efficient handling of large numbers
- Circuit construction has zero runtime overhead due to type-based approach
Errors
Circuit evaluation can fail when computing multiplicative inverses of non-invertible
elements, in which case it returns an Error.
Note that a modulus of 0 or 1 is rejected at CircuitModulus construction (try_into
returns None), so it never reaches evaluation.
Fully qualified path: core::circuit
Modules
| conversions | Helper module to convert into u384 . |
Structs
| u384 | A 384-bit unsigned integer, used for circuit values. |
Enums
| AddInputResult | The result of filling an input in the circuit instance’s data. This enum represents the state of input filling process, indicating whether all inputs have been provided or more are needed. |
Type aliases
| u96 | A 96-bit unsigned integer type used as the basic building block for multi-limb arithmetic. |
Traits
| CircuitDefinition | A trait for defining a circuit’s structure and behavior. This trait is used to define the structure of a circuit, including its inputs,… |
| IntoCircuitInputValue | Trait for converting a value to a circuit input value. |
Extern types
| CircuitData | A type representing a circuit instance data with all the inputs added. |
| CircuitInputAccumulator | Type for accumulating inputs into the circuit instance’s data. |
| U96Guarantee | A value that is guaranteed to fit in a u96. The destructor of the type verifies that the value is indeed within the range of a u96. |
Extern functions
| add_circuit_input | Fill an input in the circuit instance’s data. |
| init_circuit_data | Initializes the input data for running an instance of the circuit. |
| into_u96_guarantee | Converts ‘T’ into a ‘U96Guarantee’. ‘T’ must be a value that fits inside a u96, for example: u8, u96 or BoundedInt < 0, 12>. |
Modules
Modules
| conversions | Helper module to convert into u384 . |
conversions
Helper module to convert into u384.
Fully qualified path: core::circuit::conversions
Constants
| NZ_POW32_TYPED | — |
| NZ_POW64_TYPED | — |
| NZ_POW96_TYPED | — |
| POW32 | — |
| POW32_TYPED | — |
| POW64 | — |
| POW64_TYPED | — |
| POW96_TYPED | — |
Free functions
Impls
| AddHelperTo128By64Impl | — |
| AddHelperTo128By96Impl | — |
| AddHelperTo96By32Impl | — |
| DivRemU128By64 | — |
| DivRemU128By96 | — |
| DivRemU96By32 | — |
| DivRemU96By64 | — |
| MulHelper32By96Impl | — |
| MulHelper64By32Impl | — |
| MulHelper64By64Impl | — |
Constants
Constants
| NZ_POW32_TYPED | — |
| NZ_POW64_TYPED | — |
| NZ_POW96_TYPED | — |
| POW32 | — |
| POW32_TYPED | — |
| POW64 | — |
| POW64_TYPED | — |
| POW96_TYPED | — |
NZ_POW32_TYPED
Fully qualified path: core::circuit::conversions::NZ_POW32_TYPED
const NZ_POW32_TYPED: NonZero<BoundedInt<4294967296, 4294967296>> = 4294967296;
NZ_POW64_TYPED
Fully qualified path: core::circuit::conversions::NZ_POW64_TYPED
const NZ_POW64_TYPED: NonZero<BoundedInt<18446744073709551616, 18446744073709551616>> =
18446744073709551616;
NZ_POW96_TYPED
Fully qualified path: core::circuit::conversions::NZ_POW96_TYPED
const NZ_POW96_TYPED: NonZero<
BoundedInt<79228162514264337593543950336, 79228162514264337593543950336>,
> =
79228162514264337593543950336;
POW32
Fully qualified path: core::circuit::conversions::POW32
const POW32: felt252 = 4294967296;
POW32_TYPED
Fully qualified path: core::circuit::conversions::POW32_TYPED
const POW32_TYPED: BoundedInt<4294967296, 4294967296> = 4294967296;
POW64
Fully qualified path: core::circuit::conversions::POW64
const POW64: felt252 = 18446744073709551616;
POW64_TYPED
Fully qualified path: core::circuit::conversions::POW64_TYPED
const POW64_TYPED: BoundedInt<18446744073709551616, 18446744073709551616> = 18446744073709551616;
POW96_TYPED
Fully qualified path: core::circuit::conversions::POW96_TYPED
const POW96_TYPED: BoundedInt<79228162514264337593543950336, 79228162514264337593543950336> =
79228162514264337593543950336;
Free functions
Free functions
felt252_try_into_two_u96
Fully qualified path: core::circuit::conversions::felt252_try_into_two_u96
pub fn felt252_try_into_two_u96(
value: felt252,
) -> Option<
(BoundedInt<0, 79228162514264337593543950335>, BoundedInt<0, 79228162514264337593543950335>),
>
two_u96_into_felt252
Fully qualified path: core::circuit::conversions::two_u96_into_felt252
pub fn two_u96_into_felt252(
limb0: BoundedInt<0, 79228162514264337593543950335>,
limb1: BoundedInt<0, 79228162514264337593543950335>,
) -> felt252
Impls
Impls
| AddHelperTo128By64Impl | — |
| AddHelperTo128By96Impl | — |
| AddHelperTo96By32Impl | — |
| DivRemU128By64 | — |
| DivRemU128By96 | — |
| DivRemU96By32 | — |
| DivRemU96By64 | — |
| MulHelper32By96Impl | — |
| MulHelper64By32Impl | — |
| MulHelper64By64Impl | — |
AddHelperTo128By64Impl
Fully qualified path: core::circuit::conversions::AddHelperTo128By64Impl
impl AddHelperTo128By64Impl of AddHelper<
BoundedInt<0, 340282366920938463444927863358058659840>, BoundedInt<0, 18446744073709551615>,
>;
Impl types
Result
Fully qualified path: core::circuit::conversions::AddHelperTo128By64Impl::Result
type Result = BoundedInt<0, 340282366920938463463374607431768211455>;
AddHelperTo128By96Impl
Fully qualified path: core::circuit::conversions::AddHelperTo128By96Impl
impl AddHelperTo128By96Impl of AddHelper<
BoundedInt<0, 340282366841710300949110269838224261120>,
BoundedInt<0, 79228162514264337593543950335>,
>;
Impl types
Result
Fully qualified path: core::circuit::conversions::AddHelperTo128By96Impl::Result
type Result = BoundedInt<0, 340282366920938463463374607431768211455>;
AddHelperTo96By32Impl
Fully qualified path: core::circuit::conversions::AddHelperTo96By32Impl
impl AddHelperTo96By32Impl of AddHelper<
BoundedInt<0, 79228162514264337589248983040>, BoundedInt<0, 4294967295>,
>;
Impl types
Result
Fully qualified path: core::circuit::conversions::AddHelperTo96By32Impl::Result
type Result = BoundedInt<0, 79228162514264337593543950335>;
DivRemU128By64
Fully qualified path: core::circuit::conversions::DivRemU128By64
impl DivRemU128By64 of DivRemHelper<u128, BoundedInt<18446744073709551616, 18446744073709551616>>;
Impl types
DivT
Fully qualified path: core::circuit::conversions::DivRemU128By64::DivT
type DivT = BoundedInt<0, 18446744073709551615>;
RemT
Fully qualified path: core::circuit::conversions::DivRemU128By64::RemT
type RemT = BoundedInt<0, 18446744073709551615>;
DivRemU128By96
Fully qualified path: core::circuit::conversions::DivRemU128By96
impl DivRemU128By96 of DivRemHelper<
u128, BoundedInt<79228162514264337593543950336, 79228162514264337593543950336>,
>;
Impl types
DivT
Fully qualified path: core::circuit::conversions::DivRemU128By96::DivT
type DivT = BoundedInt<0, 4294967295>;
RemT
Fully qualified path: core::circuit::conversions::DivRemU128By96::RemT
type RemT = BoundedInt<0, 79228162514264337593543950335>;
DivRemU96By32
Fully qualified path: core::circuit::conversions::DivRemU96By32
impl DivRemU96By32 of DivRemHelper<
BoundedInt<0, 79228162514264337593543950335>, BoundedInt<4294967296, 4294967296>,
>;
Impl types
DivT
Fully qualified path: core::circuit::conversions::DivRemU96By32::DivT
type DivT = BoundedInt<0, 18446744073709551615>;
RemT
Fully qualified path: core::circuit::conversions::DivRemU96By32::RemT
type RemT = BoundedInt<0, 4294967295>;
DivRemU96By64
Fully qualified path: core::circuit::conversions::DivRemU96By64
impl DivRemU96By64 of DivRemHelper<
BoundedInt<0, 79228162514264337593543950335>,
BoundedInt<18446744073709551616, 18446744073709551616>,
>;
Impl types
DivT
Fully qualified path: core::circuit::conversions::DivRemU96By64::DivT
type DivT = BoundedInt<0, 4294967295>;
RemT
Fully qualified path: core::circuit::conversions::DivRemU96By64::RemT
type RemT = BoundedInt<0, 18446744073709551615>;
MulHelper32By96Impl
Fully qualified path: core::circuit::conversions::MulHelper32By96Impl
impl MulHelper32By96Impl of MulHelper<
BoundedInt<0, 4294967295>,
BoundedInt<79228162514264337593543950336, 79228162514264337593543950336>,
>;
Impl types
Result
Fully qualified path: core::circuit::conversions::MulHelper32By96Impl::Result
type Result = BoundedInt<0, 340282366841710300949110269838224261120>;
MulHelper64By32Impl
Fully qualified path: core::circuit::conversions::MulHelper64By32Impl
impl MulHelper64By32Impl of MulHelper<
BoundedInt<0, 18446744073709551615>, BoundedInt<4294967296, 4294967296>,
>;
Impl types
Result
Fully qualified path: core::circuit::conversions::MulHelper64By32Impl::Result
type Result = BoundedInt<0, 79228162514264337589248983040>;
MulHelper64By64Impl
Fully qualified path: core::circuit::conversions::MulHelper64By64Impl
impl MulHelper64By64Impl of MulHelper<
BoundedInt<0, 18446744073709551615>, BoundedInt<18446744073709551616, 18446744073709551616>,
>;
Impl types
Result
Fully qualified path: core::circuit::conversions::MulHelper64By64Impl::Result
type Result = BoundedInt<0, 340282366920938463444927863358058659840>;
Structs
Structs
| u384 | A 384-bit unsigned integer, used for circuit values. |
u384
A 384-bit unsigned integer, used for circuit values.
Fully qualified path: core::circuit::u384
#[derive(Copy, Drop, Debug, PartialEq)]
pub struct u384 {
pub limb0: BoundedInt<0, 79228162514264337593543950335>,
pub limb1: BoundedInt<0, 79228162514264337593543950335>,
pub limb2: BoundedInt<0, 79228162514264337593543950335>,
pub limb3: BoundedInt<0, 79228162514264337593543950335>,
}
Members
limb0
The least significant 96 bits
Fully qualified path: core::circuit::u384::limb0
pub limb0: BoundedInt<0, 79228162514264337593543950335>
limb1
Bits 96-191
Fully qualified path: core::circuit::u384::limb1
pub limb1: BoundedInt<0, 79228162514264337593543950335>
limb2
Bits 192-287
Fully qualified path: core::circuit::u384::limb2
pub limb2: BoundedInt<0, 79228162514264337593543950335>
limb3
The most significant 96 bits
Fully qualified path: core::circuit::u384::limb3
pub limb3: BoundedInt<0, 79228162514264337593543950335>
Enums
Enums
| AddInputResult | The result of filling an input in the circuit instance’s data. This enum represents the state of input filling process, indicating whether all inputs have been provided or more are needed. |
AddInputResult
The result of filling an input in the circuit instance’s data.
This enum represents the state of input filling process, indicating whether all inputs have been provided or more are needed.
Fully qualified path: core::circuit::AddInputResult
pub enum AddInputResult {
Done: CircuitData<C>,
More: CircuitInputAccumulator<C>,
}
Variants
Done
All inputs have been filled and the circuit data is complete.
Fully qualified path: core::circuit::AddInputResult::Done
Done: CircuitData<C>
More
More inputs are needed to complete the circuit instance’s data.
Fully qualified path: core::circuit::AddInputResult::More
More: CircuitInputAccumulator<C>
Type aliases
Type aliases
| u96 | A 96-bit unsigned integer type used as the basic building block for multi-limb arithmetic. |
u96
A 96-bit unsigned integer type used as the basic building block for multi-limb arithmetic.
Fully qualified path: core::circuit::u96
pub type u96 = BoundedInt<0, 79228162514264337593543950335>;
Traits
Traits
| CircuitDefinition | A trait for defining a circuit’s structure and behavior. This trait is used to define the structure of a circuit, including its inputs,… |
| IntoCircuitInputValue | Trait for converting a value to a circuit input value. |
CircuitDefinition
A trait for defining a circuit’s structure and behavior.
This trait is used to define the structure of a circuit, including its inputs,
gates, and outputs. It provides the foundation for circuit evaluation.
The CES type parameter represents a tuple of CircuitElements that together
define the circuit’s structure.
Fully qualified path: core::circuit::CircuitDefinition
pub trait CircuitDefinition<CES>
Trait types
CircuitType
The internal circuit type representing a tuple of CircuitElements.
Fully qualified path: core::circuit::CircuitDefinition::CircuitType
type CircuitType;
IntoCircuitInputValue
Trait for converting a value to a circuit input value.
Fully qualified path: core::circuit::IntoCircuitInputValue
trait IntoCircuitInputValue<T>
Trait functions
into_circuit_input_value
Fully qualified path: core::circuit::IntoCircuitInputValue::into_circuit_input_value
fn into_circuit_input_value(self: T) -> [U96Guarantee; 4]
Extern types
Extern types
| CircuitData | A type representing a circuit instance data with all the inputs added. |
| CircuitInputAccumulator | Type for accumulating inputs into the circuit instance’s data. |
| U96Guarantee | A value that is guaranteed to fit in a u96. The destructor of the type verifies that the value is indeed within the range of a u96. |
CircuitData
A type representing a circuit instance data with all the inputs added.
Fully qualified path: core::circuit::CircuitData
extern type CircuitData<C>;
CircuitInputAccumulator
Type for accumulating inputs into the circuit instance’s data.
Fully qualified path: core::circuit::CircuitInputAccumulator
extern type CircuitInputAccumulator<C>;
U96Guarantee
A value that is guaranteed to fit in a u96.
The destructor of the type verifies that the value is indeed within the range of a u96.
Fully qualified path: core::circuit::U96Guarantee
extern type U96Guarantee;
Extern functions
Extern functions
| add_circuit_input | Fill an input in the circuit instance’s data. |
| init_circuit_data | Initializes the input data for running an instance of the circuit. |
| into_u96_guarantee | Converts ‘T’ into a ‘U96Guarantee’. ‘T’ must be a value that fits inside a u96, for example: u8, u96 or BoundedInt < 0, 12>. |
add_circuit_input
Fill an input in the circuit instance’s data.
Fully qualified path: core::circuit::add_circuit_input
extern fn add_circuit_input(accumulator: CircuitInputAccumulator<C>, value: [U96Guarantee; 4]) -> AddInputResult<C> nopanic;
init_circuit_data
Initializes the input data for running an instance of the circuit.
Fully qualified path: core::circuit::init_circuit_data
extern fn init_circuit_data() -> CircuitInputAccumulator<C> implicits(RangeCheck96) nopanic;
into_u96_guarantee
Converts ‘T’ into a ‘U96Guarantee’. ‘T’ must be a value that fits inside a u96, for example: u8, u96 or BoundedInt<0, 12>.
Fully qualified path: core::circuit::into_u96_guarantee
extern fn into_u96_guarantee(val: T) -> U96Guarantee nopanic;
keccak
Keccak-256 cryptographic hash function implementation.
Main Functions
keccak_u256s_le_inputs- Hash multipleu256values in little-endian formatkeccak_u256s_be_inputs- Hash multipleu256values in big-endian formatcairo_keccak- Hash u64 words with a final partial word. Closest to the syscall input.compute_keccak_byte_array- Hash aByteArraydirectly
Examples
use core::keccak::*;
// Hash u256 values
let input = array![1_u256, 2_u256].span();
assert!(keccak_u256s_le_inputs(input) ==
0x234a9e12e9b063b60f7e3289ee9b86a731de8e7e41bd4987f10982d6a753444d);
assert!(keccak_u256s_be_inputs(input) ==
0xe0c2a7d2cc99d544061ac0ccbb083ac8976e54eed878fb1854dfe7b6ce7b0be9);
// Hash a `Bytearray`
let text: ByteArray = "Hello, Keccak!";
assert!(compute_keccak_byte_array(@text) ==
0x85c9aab73219c1e95c5b5966a4ecc8db4418c3500072a830cfb5a2d13d2c2249);
Fully qualified path: core::keccak
Free functions
| cairo_keccak | Computes the Keccak-256 hash of a byte sequence with custom padding. This function allows hashing arbitrary byte sequences by providing the input as… |
| keccak_add_u256_be | — |
Free functions
Free functions
| cairo_keccak | Computes the Keccak-256 hash of a byte sequence with custom padding. This function allows hashing arbitrary byte sequences by providing the input as… |
| keccak_add_u256_be | — |
cairo_keccak
Computes the Keccak-256 hash of a byte sequence with custom padding.
This function allows hashing arbitrary byte sequences by providing the input as 64-bit words in little-endian format and a final partial word.
Arguments
input- Array of complete 64-bit words in little-endian formatlast_input_word- Final partial word (if any)last_input_num_bytes- Number of valid bytes in the final word (0-7)
Returns
The 32-byte Keccak-256 hash as a little-endian u256
Panics
Panics if last_input_num_bytes is greater than 7.
Examples
use core::keccak::cairo_keccak;
// Hash "Hello world!" by splitting into 64-bit words in little-endian
let mut input = array![0x6f77206f6c6c6548]; // a full 8-byte word
let hash = cairo_keccak(ref input, 0x21646c72, 4); // 4 bytes of the last word
assert!(hash == 0xabea1f2503529a21734e2077c8b584d7bee3f45550c2d2f12a198ea908e1d0ec);
Fully qualified path: core::keccak::cairo_keccak
pub fn cairo_keccak(ref input: Array<u64>, last_input_word: u64, last_input_num_bytes: u32) -> u256
keccak_add_u256_be
Fully qualified path: core::keccak::keccak_add_u256_be
fn keccak_add_u256_be(ref keccak_input: Array<u64>, v: u256)
integer
Integer types and operations.
This module provides the built-in integer types and their associated operations.
Integer Types
The following integer types are available:
- Unsigned integers:
u8,u16,u32,u64,u128,u256 - Signed integers:
i8,i16,i32,i64,i128
Operations
Integer types implement various traits that enable common operations:
- Basic arithmetic via
Add,Sub,Mul,Div,RemandDivRem - Bitwise operations via
BitAnd,BitOr,BitXor, andBitNot - Comparison via
PartialEqandPartialOrd - Safe arithmetic via
CheckedAdd,CheckedSub,CheckedMul - Wrapping arithmetic via
WrappingAdd,WrappingSub,WrappingMul - Overflow handling via
OverflowingAdd,OverflowingSub,OverflowingMul
Examples
Basic operators:
let a: u8 = 5;
let b: u8 = 10;
assert_eq!(a + b, 15);
assert_eq!(a * b, 50);
assert_eq!(a & b, 0);
assert!(a < b);
Checked operations:
use core::num::traits::{CheckedAdd, Bounded};
let max: u8 = Bounded::MAX;
assert!(max.checked_add(1_u8).is_none());
Conversions
Integers can be converted between different types using:
TryIntofor potentially fallible conversionsIntofor infallible conversions to wider types
Fully qualified path: core::integer
Enums
Extern functions
Enums
Enums
U128sFromFelt252Result
Fully qualified path: core::integer::U128sFromFelt252Result
enum U128sFromFelt252Result {
Narrow: u128,
Wide: (u128, u128),
}
Variants
Narrow
Fully qualified path: core::integer::U128sFromFelt252Result::Narrow
Narrow: u128
Wide
Fully qualified path: core::integer::U128sFromFelt252Result::Wide
Wide: (u128, u128)
Extern functions
Extern functions
u128s_from_felt252
Fully qualified path: core::integer::u128s_from_felt252
extern fn u128s_from_felt252(a: felt252) -> U128sFromFelt252Result implicits(RangeCheck) nopanic;
internal
Fully qualified path: core::internal
Modules
Modules
Modules
bounded_int
Fully qualified path: core::internal::bounded_int
Modules
| constrain0 | — |
| trim_impl | — |
| neg_felt252 | Helper implementation for NegFelt252 . |
Type aliases
Impl aliases
Traits
| AddHelper | A helper trait for adding two BoundedInt instances. |
| DivRemHelper | A helper trait for dividing two BoundedInt instances. |
| MulHelper | A helper trait for multiplying two BoundedInt instances. |
| SubHelper | A helper trait for subtracting two BoundedInt instances. |
| ConstrainHelper | A helper trait for constraining a BoundedInt instance. |
| TrimMinHelper | A helper trait for trimming a BoundedInt instance’s min value. |
| TrimMaxHelper | A helper trait for trimming a BoundedInt instance’s max value. |
| NegFelt252 | Returns the negation of the given felt252 value. |
| NegateHelper | A helper trait for negating a BoundedInt instance. |
Impls
Extern types
Extern functions
| bounded_int_div_rem | — |
| downcast | Downcasts FromType to ToType - for types where conversion may fail. If done for wrong types would cause a compiler panic at the Sierra stage. |
| upcast | Upcasts FromType to ToType - for types where conversion is always legal. If done for wrong types would cause a compiler panic at the Sierra stage. |
| bounded_int_add | — |
| bounded_int_sub | — |
| bounded_int_mul | — |
| bounded_int_constrain | — |
| bounded_int_trim_min | — |
| bounded_int_trim_max | — |
| bounded_int_is_zero | — |
Modules
Modules
| constrain0 | — |
| trim_impl | — |
| neg_felt252 | Helper implementation for NegFelt252 . |
constrain0
Fully qualified path: core::internal::bounded_int::constrain0
trim_impl
Fully qualified path: core::internal::bounded_int::trim_impl
neg_felt252
Helper implementation for NegFelt252.
Fully qualified path: core::internal::bounded_int::neg_felt252
Type aliases
Type aliases
UnitInt
Fully qualified path: core::internal::bounded_int::UnitInt
pub type UnitInt<const VALUE> = BoundedInt<VALUE, VALUE>;
Impl aliases
Impl aliases
BoundedIntSerde
Fully qualified path: core::internal::bounded_int::BoundedIntSerde
impl BoundedIntSerde = crate::serde::into_felt252_based::SerdeImpl<BoundedInt<MIN, MAX>>;
BoundedIntDebug
Fully qualified path: core::internal::bounded_int::BoundedIntDebug
impl BoundedIntDebug = crate::fmt::into_felt252_based::DebugImpl<BoundedInt<MIN, MAX>>;
I8Constrain0
Fully qualified path: core::internal::bounded_int::I8Constrain0
impl I8Constrain0 = constrain0::Impl<i8, -0x80, 0x7f>;
I16Constrain0
Fully qualified path: core::internal::bounded_int::I16Constrain0
impl I16Constrain0 = constrain0::Impl<i16, -0x8000, 0x7fff>;
I32Constrain0
Fully qualified path: core::internal::bounded_int::I32Constrain0
impl I32Constrain0 = constrain0::Impl<i32, -0x80000000, 0x7fffffff>;
I64Constrain0
Fully qualified path: core::internal::bounded_int::I64Constrain0
impl I64Constrain0 = constrain0::Impl<i64, -0x8000000000000000, 0x7fffffffffffffff>;
I128Constrain0
Fully qualified path: core::internal::bounded_int::I128Constrain0
impl I128Constrain0 =
constrain0::Impl<i128, -0x80000000000000000000000000000000, 0x7fffffffffffffffffffffffffffffff>;
U8TrimBelow
Fully qualified path: core::internal::bounded_int::U8TrimBelow
impl U8TrimBelow = trim_impl::Min<u8, 1, 0xff>;
U8TrimAbove
Fully qualified path: core::internal::bounded_int::U8TrimAbove
impl U8TrimAbove = trim_impl::Max<u8, 0, 0xfe>;
I8TrimBelow
Fully qualified path: core::internal::bounded_int::I8TrimBelow
impl I8TrimBelow = trim_impl::Min<i8, -0x7f, 0x7f>;
I8TrimAbove
Fully qualified path: core::internal::bounded_int::I8TrimAbove
impl I8TrimAbove = trim_impl::Max<i8, -0x80, 0x7e>;
U16TrimBelow
Fully qualified path: core::internal::bounded_int::U16TrimBelow
impl U16TrimBelow = trim_impl::Min<u16, 1, 0xffff>;
U16TrimAbove
Fully qualified path: core::internal::bounded_int::U16TrimAbove
impl U16TrimAbove = trim_impl::Max<u16, 0, 0xfffe>;
I16TrimBelow
Fully qualified path: core::internal::bounded_int::I16TrimBelow
impl I16TrimBelow = trim_impl::Min<i16, -0x7fff, 0x7fff>;
I16TrimAbove
Fully qualified path: core::internal::bounded_int::I16TrimAbove
impl I16TrimAbove = trim_impl::Max<i16, -0x8000, 0x7ffe>;
U32TrimBelow
Fully qualified path: core::internal::bounded_int::U32TrimBelow
impl U32TrimBelow = trim_impl::Min<u32, 1, 0xffffffff>;
U32TrimAbove
Fully qualified path: core::internal::bounded_int::U32TrimAbove
impl U32TrimAbove = trim_impl::Max<u32, 0, 0xfffffffe>;
I32TrimBelow
Fully qualified path: core::internal::bounded_int::I32TrimBelow
impl I32TrimBelow = trim_impl::Min<i32, -0x7fffffff, 0x7fffffff>;
I32TrimAbove
Fully qualified path: core::internal::bounded_int::I32TrimAbove
impl I32TrimAbove = trim_impl::Max<i32, -0x80000000, 0x7ffffffe>;
U64TrimBelow
Fully qualified path: core::internal::bounded_int::U64TrimBelow
impl U64TrimBelow = trim_impl::Min<u64, 1, 0xffffffffffffffff>;
U64TrimAbove
Fully qualified path: core::internal::bounded_int::U64TrimAbove
impl U64TrimAbove = trim_impl::Max<u64, 0, 0xfffffffffffffffe>;
I64TrimBelow
Fully qualified path: core::internal::bounded_int::I64TrimBelow
impl I64TrimBelow = trim_impl::Min<i64, -0x7fffffffffffffff, 0x7fffffffffffffff>;
I64TrimAbove
Fully qualified path: core::internal::bounded_int::I64TrimAbove
impl I64TrimAbove = trim_impl::Max<i64, -0x8000000000000000, 0x7ffffffffffffffe>;
U128TrimBelow
Fully qualified path: core::internal::bounded_int::U128TrimBelow
impl U128TrimBelow = trim_impl::Min<u128, 1, 0xffffffffffffffffffffffffffffffff>;
U128TrimAbove
Fully qualified path: core::internal::bounded_int::U128TrimAbove
impl U128TrimAbove = trim_impl::Max<u128, 0, 0xfffffffffffffffffffffffffffffffe>;
I128TrimBelow
Fully qualified path: core::internal::bounded_int::I128TrimBelow
impl I128TrimBelow =
trim_impl::Min<i128, -0x7fffffffffffffffffffffffffffffff, 0x7fffffffffffffffffffffffffffffff>;
I128TrimAbove
Fully qualified path: core::internal::bounded_int::I128TrimAbove
impl I128TrimAbove =
trim_impl::Max<i128, -0x80000000000000000000000000000000, 0x7ffffffffffffffffffffffffffffffe>;
NegFelt2520
Fully qualified path: core::internal::bounded_int::NegFelt2520
impl NegFelt2520 = neg_felt252::Impl<0, 0>;
NegFelt2521
Fully qualified path: core::internal::bounded_int::NegFelt2521
impl NegFelt2521 = neg_felt252::Impl<1, -1>;
NegFelt252Minus1
Fully qualified path: core::internal::bounded_int::NegFelt252Minus1
impl NegFelt252Minus1 = neg_felt252::Impl<-1, 1>;
NegFelt2520x7e
Fully qualified path: core::internal::bounded_int::NegFelt2520x7e
impl NegFelt2520x7e = neg_felt252::Impl<0x7e, -0x7e>;
NegFelt252Minus0x7e
Fully qualified path: core::internal::bounded_int::NegFelt252Minus0x7e
impl NegFelt252Minus0x7e = neg_felt252::Impl<-0x7e, 0x7e>;
NegFelt2520x7f
Fully qualified path: core::internal::bounded_int::NegFelt2520x7f
impl NegFelt2520x7f = neg_felt252::Impl<0x7f, -0x7f>;
NegFelt252Minus0x7f
Fully qualified path: core::internal::bounded_int::NegFelt252Minus0x7f
impl NegFelt252Minus0x7f = neg_felt252::Impl<-0x7f, 0x7f>;
NegFelt2520x80
Fully qualified path: core::internal::bounded_int::NegFelt2520x80
impl NegFelt2520x80 = neg_felt252::Impl<0x80, -0x80>;
NegFelt252Minus0x80
Fully qualified path: core::internal::bounded_int::NegFelt252Minus0x80
impl NegFelt252Minus0x80 = neg_felt252::Impl<-0x80, 0x80>;
NegFelt2520x7ffe
Fully qualified path: core::internal::bounded_int::NegFelt2520x7ffe
impl NegFelt2520x7ffe = neg_felt252::Impl<0x7ffe, -0x7ffe>;
NegFelt252Minus0x7ffe
Fully qualified path: core::internal::bounded_int::NegFelt252Minus0x7ffe
impl NegFelt252Minus0x7ffe = neg_felt252::Impl<-0x7ffe, 0x7ffe>;
NegFelt2520x7fff
Fully qualified path: core::internal::bounded_int::NegFelt2520x7fff
impl NegFelt2520x7fff = neg_felt252::Impl<0x7fff, -0x7fff>;
NegFelt252Minus0x7fff
Fully qualified path: core::internal::bounded_int::NegFelt252Minus0x7fff
impl NegFelt252Minus0x7fff = neg_felt252::Impl<-0x7fff, 0x7fff>;
NegFelt2520x8000
Fully qualified path: core::internal::bounded_int::NegFelt2520x8000
impl NegFelt2520x8000 = neg_felt252::Impl<0x8000, -0x8000>;
NegFelt252Minus0x8000
Fully qualified path: core::internal::bounded_int::NegFelt252Minus0x8000
impl NegFelt252Minus0x8000 = neg_felt252::Impl<-0x8000, 0x8000>;
NegFelt2520x7ffffffe
Fully qualified path: core::internal::bounded_int::NegFelt2520x7ffffffe
impl NegFelt2520x7ffffffe = neg_felt252::Impl<0x7ffffffe, -0x7ffffffe>;
NegFelt252Minus0x7ffffffe
Fully qualified path: core::internal::bounded_int::NegFelt252Minus0x7ffffffe
impl NegFelt252Minus0x7ffffffe = neg_felt252::Impl<-0x7ffffffe, 0x7ffffffe>;
NegFelt2520x7fffffff
Fully qualified path: core::internal::bounded_int::NegFelt2520x7fffffff
impl NegFelt2520x7fffffff = neg_felt252::Impl<0x7fffffff, -0x7fffffff>;
NegFelt252Minus0x7fffffff
Fully qualified path: core::internal::bounded_int::NegFelt252Minus0x7fffffff
impl NegFelt252Minus0x7fffffff = neg_felt252::Impl<-0x7fffffff, 0x7fffffff>;
NegFelt2520x80000000
Fully qualified path: core::internal::bounded_int::NegFelt2520x80000000
impl NegFelt2520x80000000 = neg_felt252::Impl<0x80000000, -0x80000000>;
NegFelt252Minus0x80000000
Fully qualified path: core::internal::bounded_int::NegFelt252Minus0x80000000
impl NegFelt252Minus0x80000000 = neg_felt252::Impl<-0x80000000, 0x80000000>;
NegFelt2520x7ffffffffffffffe
Fully qualified path: core::internal::bounded_int::NegFelt2520x7ffffffffffffffe
impl NegFelt2520x7ffffffffffffffe = neg_felt252::Impl<0x7ffffffffffffffe, -0x7ffffffffffffffe>;
NegFelt252Minus0x7ffffffffffffffe
Fully qualified path: core::internal::bounded_int::NegFelt252Minus0x7ffffffffffffffe
impl NegFelt252Minus0x7ffffffffffffffe = neg_felt252::Impl<-0x7ffffffffffffffe, 0x7ffffffffffffffe>;
NegFelt2520x7fffffffffffffff
Fully qualified path: core::internal::bounded_int::NegFelt2520x7fffffffffffffff
impl NegFelt2520x7fffffffffffffff = neg_felt252::Impl<0x7fffffffffffffff, -0x7fffffffffffffff>;
NegFelt252Minus0x7fffffffffffffff
Fully qualified path: core::internal::bounded_int::NegFelt252Minus0x7fffffffffffffff
impl NegFelt252Minus0x7fffffffffffffff = neg_felt252::Impl<-0x7fffffffffffffff, 0x7fffffffffffffff>;
NegFelt2520x8000000000000000
Fully qualified path: core::internal::bounded_int::NegFelt2520x8000000000000000
impl NegFelt2520x8000000000000000 = neg_felt252::Impl<0x8000000000000000, -0x8000000000000000>;
NegFelt252Minus0x8000000000000000
Fully qualified path: core::internal::bounded_int::NegFelt252Minus0x8000000000000000
impl NegFelt252Minus0x8000000000000000 = neg_felt252::Impl<-0x8000000000000000, 0x8000000000000000>;
NegFelt2520x7ffffffffffffffffffffffffffffffe
Fully qualified path: core::internal::bounded_int::NegFelt2520x7ffffffffffffffffffffffffffffffe
impl NegFelt2520x7ffffffffffffffffffffffffffffffe =
neg_felt252::Impl<0x7ffffffffffffffffffffffffffffffe, -0x7ffffffffffffffffffffffffffffffe>;
NegFelt252Minus0x7ffffffffffffffffffffffffffffffe
Fully qualified path: core::internal::bounded_int::NegFelt252Minus0x7ffffffffffffffffffffffffffffffe
impl NegFelt252Minus0x7ffffffffffffffffffffffffffffffe =
neg_felt252::Impl<-0x7ffffffffffffffffffffffffffffffe, 0x7ffffffffffffffffffffffffffffffe>;
NegFelt2520x7fffffffffffffffffffffffffffffff
Fully qualified path: core::internal::bounded_int::NegFelt2520x7fffffffffffffffffffffffffffffff
impl NegFelt2520x7fffffffffffffffffffffffffffffff =
neg_felt252::Impl<0x7fffffffffffffffffffffffffffffff, -0x7fffffffffffffffffffffffffffffff>;
NegFelt252Minus0x7fffffffffffffffffffffffffffffff
Fully qualified path: core::internal::bounded_int::NegFelt252Minus0x7fffffffffffffffffffffffffffffff
impl NegFelt252Minus0x7fffffffffffffffffffffffffffffff =
neg_felt252::Impl<-0x7fffffffffffffffffffffffffffffff, 0x7fffffffffffffffffffffffffffffff>;
NegFelt2520x80000000000000000000000000000000
Fully qualified path: core::internal::bounded_int::NegFelt2520x80000000000000000000000000000000
impl NegFelt2520x80000000000000000000000000000000 =
neg_felt252::Impl<0x80000000000000000000000000000000, -0x80000000000000000000000000000000>;
NegFelt252Minus0x80000000000000000000000000000000
Fully qualified path: core::internal::bounded_int::NegFelt252Minus0x80000000000000000000000000000000
impl NegFelt252Minus0x80000000000000000000000000000000 =
neg_felt252::Impl<-0x80000000000000000000000000000000, 0x80000000000000000000000000000000>;
Traits
Traits
| AddHelper | A helper trait for adding two BoundedInt instances. |
| DivRemHelper | A helper trait for dividing two BoundedInt instances. |
| MulHelper | A helper trait for multiplying two BoundedInt instances. |
| SubHelper | A helper trait for subtracting two BoundedInt instances. |
| ConstrainHelper | A helper trait for constraining a BoundedInt instance. |
| TrimMinHelper | A helper trait for trimming a BoundedInt instance’s min value. |
| TrimMaxHelper | A helper trait for trimming a BoundedInt instance’s max value. |
| NegFelt252 | Returns the negation of the given felt252 value. |
| NegateHelper | A helper trait for negating a BoundedInt instance. |
AddHelper
A helper trait for adding two BoundedInt instances.
Fully qualified path: core::internal::bounded_int::AddHelper
pub trait AddHelper<Lhs, Rhs>
Trait types
Result
Fully qualified path: core::internal::bounded_int::AddHelper::Result
type Result;
DivRemHelper
A helper trait for dividing two BoundedInt instances.
Fully qualified path: core::internal::bounded_int::DivRemHelper
pub trait DivRemHelper<Lhs, Rhs>
Trait types
DivT
Fully qualified path: core::internal::bounded_int::DivRemHelper::DivT
type DivT;
RemT
Fully qualified path: core::internal::bounded_int::DivRemHelper::RemT
type RemT;
MulHelper
A helper trait for multiplying two BoundedInt instances.
Fully qualified path: core::internal::bounded_int::MulHelper
pub trait MulHelper<Lhs, Rhs>
Trait types
Result
Fully qualified path: core::internal::bounded_int::MulHelper::Result
type Result;
SubHelper
A helper trait for subtracting two BoundedInt instances.
Fully qualified path: core::internal::bounded_int::SubHelper
pub trait SubHelper<Lhs, Rhs>
Trait types
Result
Fully qualified path: core::internal::bounded_int::SubHelper::Result
type Result;
ConstrainHelper
A helper trait for constraining a BoundedInt instance.
Fully qualified path: core::internal::bounded_int::ConstrainHelper
pub trait ConstrainHelper<T, const BOUNDARY>
Trait types
LowT
Fully qualified path: core::internal::bounded_int::ConstrainHelper::LowT
type LowT;
HighT
Fully qualified path: core::internal::bounded_int::ConstrainHelper::HighT
type HighT;
TrimMinHelper
A helper trait for trimming a BoundedInt instance’s min value.
Fully qualified path: core::internal::bounded_int::TrimMinHelper
pub trait TrimMinHelper<T>
Trait types
Target
Fully qualified path: core::internal::bounded_int::TrimMinHelper::Target
type Target;
TrimMaxHelper
A helper trait for trimming a BoundedInt instance’s max value.
Fully qualified path: core::internal::bounded_int::TrimMaxHelper
pub trait TrimMaxHelper<T>
Trait types
Target
Fully qualified path: core::internal::bounded_int::TrimMaxHelper::Target
type Target;
NegFelt252
Returns the negation of the given felt252 value.
Fully qualified path: core::internal::bounded_int::NegFelt252
trait NegFelt252<const NUM>
Trait constants
VALUE
The negation of the given felt252 value.
Fully qualified path: core::internal::bounded_int::NegFelt252::VALUE
const VALUE: felt252;
NegateHelper
A helper trait for negating a BoundedInt instance.
Fully qualified path: core::internal::bounded_int::NegateHelper
pub trait NegateHelper<T>
Trait functions
negate
Negates the given value.
Fully qualified path: core::internal::bounded_int::NegateHelper::negate
fn negate(self: T) -> NegateHelper<T>Result
Trait types
Result
The result of negating the given value.
Fully qualified path: core::internal::bounded_int::NegateHelper::Result
type Result;
Impls
Impls
BoundedIntCopy
Fully qualified path: core::internal::bounded_int::BoundedIntCopy
impl BoundedIntCopy<MIN, MAX> of Copy<BoundedInt<MIN, MAX>>;
BoundedIntDrop
Fully qualified path: core::internal::bounded_int::BoundedIntDrop
impl BoundedIntDrop<MIN, MAX> of Drop<BoundedInt<MIN, MAX>>;
NumericLiteralBoundedInt
Fully qualified path: core::internal::bounded_int::NumericLiteralBoundedInt
impl NumericLiteralBoundedInt<MIN, MAX> of NumericLiteral<BoundedInt<MIN, MAX>>;
BoundedIntIntoFelt252
Fully qualified path: core::internal::bounded_int::BoundedIntIntoFelt252
impl BoundedIntIntoFelt252<MIN, MAX> of Into<BoundedInt<MIN, MAX>, felt252>;
Impl functions
into
Fully qualified path: core::internal::bounded_int::BoundedIntIntoFelt252::into
fn into(self: BoundedInt<MIN, MAX>) -> felt252
Felt252TryIntoBoundedInt
Fully qualified path: core::internal::bounded_int::Felt252TryIntoBoundedInt
impl Felt252TryIntoBoundedInt<MIN, MAX> of TryInto<felt252, BoundedInt<MIN, MAX>>;
Impl functions
try_into
Fully qualified path: core::internal::bounded_int::Felt252TryIntoBoundedInt::try_into
fn try_into(self: felt252) -> Option<BoundedInt<MIN, MAX>>
BoundedIntPartialEq
Fully qualified path: core::internal::bounded_int::BoundedIntPartialEq
impl BoundedIntPartialEq<MIN, MAX> of PartialEq<BoundedInt<MIN, MAX>>;
Impl functions
eq
Fully qualified path: core::internal::bounded_int::BoundedIntPartialEq::eq
fn eq(lhs: @BoundedInt<MIN, MAX>, rhs: @BoundedInt<MIN, MAX>) -> bool
AddBI01BI01Helper
Fully qualified path: core::internal::bounded_int::AddBI01BI01Helper
impl AddBI01BI01Helper of AddHelper<BoundedInt<0, 1>, BoundedInt<0, 1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::AddBI01BI01Helper::Result
type Result = BoundedInt<0, 2>;
AddBI02BI01Helper
Fully qualified path: core::internal::bounded_int::AddBI02BI01Helper
impl AddBI02BI01Helper of AddHelper<BoundedInt<0, 2>, BoundedInt<0, 1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::AddBI02BI01Helper::Result
type Result = BoundedInt<0, 3>;
AddOneToU8Helper
Fully qualified path: core::internal::bounded_int::AddOneToU8Helper
impl AddOneToU8Helper of AddHelper<BoundedInt<0, 254>, BoundedInt<1, 1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::AddOneToU8Helper::Result
type Result = BoundedInt<1, 255>;
AddOneToU16Helper
Fully qualified path: core::internal::bounded_int::AddOneToU16Helper
impl AddOneToU16Helper of AddHelper<BoundedInt<0, 65534>, BoundedInt<1, 1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::AddOneToU16Helper::Result
type Result = BoundedInt<1, 65535>;
AddOneToU32Helper
Fully qualified path: core::internal::bounded_int::AddOneToU32Helper
impl AddOneToU32Helper of AddHelper<BoundedInt<0, 4294967294>, BoundedInt<1, 1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::AddOneToU32Helper::Result
type Result = BoundedInt<1, 4294967295>;
AddOneToU64Helper
Fully qualified path: core::internal::bounded_int::AddOneToU64Helper
impl AddOneToU64Helper of AddHelper<BoundedInt<0, 18446744073709551614>, BoundedInt<1, 1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::AddOneToU64Helper::Result
type Result = BoundedInt<1, 18446744073709551615>;
AddOneToU128Helper
Fully qualified path: core::internal::bounded_int::AddOneToU128Helper
impl AddOneToU128Helper of AddHelper<
BoundedInt<0, 340282366920938463463374607431768211454>, BoundedInt<1, 1>,
>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::AddOneToU128Helper::Result
type Result = BoundedInt<1, 340282366920938463463374607431768211455>;
AddOneToI8Helper
Fully qualified path: core::internal::bounded_int::AddOneToI8Helper
impl AddOneToI8Helper of AddHelper<BoundedInt<-128, 126>, BoundedInt<1, 1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::AddOneToI8Helper::Result
type Result = BoundedInt<-127, 127>;
AddOneToI16Helper
Fully qualified path: core::internal::bounded_int::AddOneToI16Helper
impl AddOneToI16Helper of AddHelper<BoundedInt<-32768, 32766>, BoundedInt<1, 1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::AddOneToI16Helper::Result
type Result = BoundedInt<-32767, 32767>;
AddOneToI32Helper
Fully qualified path: core::internal::bounded_int::AddOneToI32Helper
impl AddOneToI32Helper of AddHelper<BoundedInt<-2147483648, 2147483646>, BoundedInt<1, 1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::AddOneToI32Helper::Result
type Result = BoundedInt<-2147483647, 2147483647>;
AddOneToI64Helper
Fully qualified path: core::internal::bounded_int::AddOneToI64Helper
impl AddOneToI64Helper of AddHelper<
BoundedInt<-9223372036854775808, 9223372036854775806>, BoundedInt<1, 1>,
>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::AddOneToI64Helper::Result
type Result = BoundedInt<-9223372036854775807, 9223372036854775807>;
AddOneToI128Helper
Fully qualified path: core::internal::bounded_int::AddOneToI128Helper
impl AddOneToI128Helper of AddHelper<
BoundedInt<-170141183460469231731687303715884105728, 170141183460469231731687303715884105726>,
BoundedInt<1, 1>,
>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::AddOneToI128Helper::Result
type Result =
BoundedInt<-170141183460469231731687303715884105727, 170141183460469231731687303715884105727>;
SubOneToU8Helper
Fully qualified path: core::internal::bounded_int::SubOneToU8Helper
impl SubOneToU8Helper of SubHelper<BoundedInt<1, 255>, BoundedInt<1, 1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::SubOneToU8Helper::Result
type Result = BoundedInt<0, 254>;
SubOneToU16Helper
Fully qualified path: core::internal::bounded_int::SubOneToU16Helper
impl SubOneToU16Helper of SubHelper<BoundedInt<1, 65535>, BoundedInt<1, 1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::SubOneToU16Helper::Result
type Result = BoundedInt<0, 65534>;
SubOneToU32Helper
Fully qualified path: core::internal::bounded_int::SubOneToU32Helper
impl SubOneToU32Helper of SubHelper<BoundedInt<1, 4294967295>, BoundedInt<1, 1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::SubOneToU32Helper::Result
type Result = BoundedInt<0, 4294967294>;
SubOneToU64Helper
Fully qualified path: core::internal::bounded_int::SubOneToU64Helper
impl SubOneToU64Helper of SubHelper<BoundedInt<1, 18446744073709551615>, BoundedInt<1, 1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::SubOneToU64Helper::Result
type Result = BoundedInt<0, 18446744073709551614>;
SubOneToU128Helper
Fully qualified path: core::internal::bounded_int::SubOneToU128Helper
impl SubOneToU128Helper of SubHelper<
BoundedInt<1, 340282366920938463463374607431768211455>, BoundedInt<1, 1>,
>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::SubOneToU128Helper::Result
type Result = BoundedInt<0, 340282366920938463463374607431768211454>;
SubOneToI8Helper
Fully qualified path: core::internal::bounded_int::SubOneToI8Helper
impl SubOneToI8Helper of SubHelper<BoundedInt<-127, 127>, BoundedInt<1, 1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::SubOneToI8Helper::Result
type Result = BoundedInt<-128, 126>;
SubOneToI16Helper
Fully qualified path: core::internal::bounded_int::SubOneToI16Helper
impl SubOneToI16Helper of SubHelper<BoundedInt<-32767, 32767>, BoundedInt<1, 1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::SubOneToI16Helper::Result
type Result = BoundedInt<-32768, 32766>;
SubOneToI32Helper
Fully qualified path: core::internal::bounded_int::SubOneToI32Helper
impl SubOneToI32Helper of SubHelper<BoundedInt<-2147483647, 2147483647>, BoundedInt<1, 1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::SubOneToI32Helper::Result
type Result = BoundedInt<-2147483648, 2147483646>;
SubOneToI64Helper
Fully qualified path: core::internal::bounded_int::SubOneToI64Helper
impl SubOneToI64Helper of SubHelper<
BoundedInt<-9223372036854775807, 9223372036854775807>, BoundedInt<1, 1>,
>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::SubOneToI64Helper::Result
type Result = BoundedInt<-9223372036854775808, 9223372036854775806>;
SubOneToI128Helper
Fully qualified path: core::internal::bounded_int::SubOneToI128Helper
impl SubOneToI128Helper of SubHelper<
BoundedInt<-170141183460469231731687303715884105727, 170141183460469231731687303715884105727>,
BoundedInt<1, 1>,
>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::SubOneToI128Helper::Result
type Result =
BoundedInt<-170141183460469231731687303715884105728, 170141183460469231731687303715884105726>;
NonZeroMulHelper
Fully qualified path: core::internal::bounded_int::NonZeroMulHelper
impl NonZeroMulHelper<
Lhs, Rhs, impl H: MulHelper<Lhs, Rhs>,
> of MulHelper<NonZero<Lhs>, NonZero<Rhs>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::NonZeroMulHelper::Result
type Result = NonZero<Result>;
NonZeroConstrainHelper
Fully qualified path: core::internal::bounded_int::NonZeroConstrainHelper
impl NonZeroConstrainHelper<
T, BOUNDARY, impl H: ConstrainHelper<T, BOUNDARY>,
> of ConstrainHelper<NonZero<T>, BOUNDARY>;
Impl types
LowT
Fully qualified path: core::internal::bounded_int::NonZeroConstrainHelper::LowT
type LowT = NonZero<LowT>;
HighT
Fully qualified path: core::internal::bounded_int::NonZeroConstrainHelper::HighT
type HighT = NonZero<HighT>;
MulMinus1
Fully qualified path: core::internal::bounded_int::MulMinus1
impl MulMinus1<
MIN, MAX, impl NegMin: NegFelt252<MIN>, impl NegMax: NegFelt252<MAX>,
> of MulHelper<BoundedInt<MIN, MAX>, BoundedInt<-1, -1>>;
Impl types
Result
Fully qualified path: core::internal::bounded_int::MulMinus1::Result
type Result = BoundedInt<VALUE, VALUE>;
NonZeroMulMinusOneNegateHelper
Fully qualified path: core::internal::bounded_int::NonZeroMulMinusOneNegateHelper
impl NonZeroMulMinusOneNegateHelper<
T, impl H: MulHelper<T, core::internal::bounded_int::BoundedInt<-1, -1>>,
> of NegateHelper<NonZero<T>>;
Impl functions
negate
Fully qualified path: core::internal::bounded_int::NonZeroMulMinusOneNegateHelper::negate
fn negate(self: NonZero<T>) -> NonZero<Result>
Impl types
Result
Fully qualified path: core::internal::bounded_int::NonZeroMulMinusOneNegateHelper::Result
type Result = NonZero<Result>;
Extern types
Extern types
BoundedInt
Fully qualified path: core::internal::bounded_int::BoundedInt
pub extern type BoundedInt<const MIN, const MAX>;
BoundedIntGuarantee
Fully qualified path: core::internal::bounded_int::BoundedIntGuarantee
pub(crate) extern type BoundedIntGuarantee<const MIN, const MAX>;
Extern functions
Extern functions
| bounded_int_div_rem | — |
| downcast | Downcasts FromType to ToType - for types where conversion may fail. If done for wrong types would cause a compiler panic at the Sierra stage. |
| upcast | Upcasts FromType to ToType - for types where conversion is always legal. If done for wrong types would cause a compiler panic at the Sierra stage. |
| bounded_int_add | — |
| bounded_int_sub | — |
| bounded_int_mul | — |
| bounded_int_constrain | — |
| bounded_int_trim_min | — |
| bounded_int_trim_max | — |
| bounded_int_is_zero | — |
bounded_int_div_rem
Fully qualified path: core::internal::bounded_int::bounded_int_div_rem
extern fn bounded_int_div_rem(lhs: Lhs, rhs: NonZero<Rhs>) -> (DivT, RemT) implicits(RangeCheck) nopanic;
downcast
Downcasts FromType to ToType - for types where conversion may fail.
If done for wrong types would cause a compiler panic at the Sierra stage.
Fully qualified path: core::internal::bounded_int::downcast
pub extern fn downcast(x: FromType) -> Option<ToType> implicits(RangeCheck) nopanic;
upcast
Upcasts FromType to ToType - for types where conversion is always legal.
If done for wrong types would cause a compiler panic at the Sierra stage.
Fully qualified path: core::internal::bounded_int::upcast
pub extern fn upcast(x: FromType) -> ToType nopanic;
bounded_int_add
Fully qualified path: core::internal::bounded_int::bounded_int_add
extern fn bounded_int_add(lhs: Lhs, rhs: Rhs) -> Result nopanic;
bounded_int_sub
Fully qualified path: core::internal::bounded_int::bounded_int_sub
extern fn bounded_int_sub(lhs: Lhs, rhs: Rhs) -> Result nopanic;
bounded_int_mul
Fully qualified path: core::internal::bounded_int::bounded_int_mul
extern fn bounded_int_mul(lhs: Lhs, rhs: Rhs) -> Result nopanic;
bounded_int_constrain
Fully qualified path: core::internal::bounded_int::bounded_int_constrain
extern fn bounded_int_constrain(value: T) -> Result<LowT, HighT> implicits(RangeCheck) nopanic;
bounded_int_trim_min
Fully qualified path: core::internal::bounded_int::bounded_int_trim_min
extern fn bounded_int_trim_min(value: T) -> OptionRev<Target> nopanic;
bounded_int_trim_max
Fully qualified path: core::internal::bounded_int::bounded_int_trim_max
extern fn bounded_int_trim_max(value: T) -> OptionRev<Target> nopanic;
bounded_int_is_zero
Fully qualified path: core::internal::bounded_int::bounded_int_is_zero
extern fn bounded_int_is_zero(value: T) -> IsZeroResult<T> nopanic;
array
A contiguous collection of elements of the same type in memory, written
Array<T>.
Arrays have O(1) indexing, O(1) push and O(1) pop (from the front).
Arrays can only be mutated by appending to the end or popping from the front.
Examples
You can explicitly create an Array with ArrayTrait::new:
let arr: Array<usize> = ArrayTrait::new();
…or by using the array! macro:
let arr: Array<usize> = array![];
let arr: Array<usize> = array![1, 2, 3, 4, 5];
You can append values onto the end of an array:
let mut arr = array![1, 2];
arr.append(3);
Popping values from the front works like this:
let mut arr = array![1, 2];
let one = arr.pop_front(); // Returns Some(1)
Arrays support indexing (through the IndexView trait):
let arr = array![1, 2, 3];
let three = arr[2]; // Returns a snapshot (@T)
Arrays can be converted to Spans for read-only access:
let arr = array![1, 2, 3];
let span = arr.span();
A span can be manipulated without affecting the original array:
let mut arr = array![1, 2, 3];
let mut span = arr.span();
span.pop_back();
assert!(arr == array![1, 2, 3]);
Fully qualified path: core::array
Extern functions
Extern functions
Extern functions
array_slice
Fully qualified path: core::array::array_slice
extern fn array_slice(arr: @Array<T>, start: u32, length: u32) -> Option<@Array<T>> implicits(RangeCheck) nopanic;