Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/starknet-types-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-types-core"
version = "0.2.2"
version = "0.2.3"
edition = "2021"
license = "MIT"
homepage = "https://github.com/starknet-io/types-rs"
Expand All @@ -15,6 +15,7 @@ lambdaworks-math = { version = "0.13.0", default-features = false }
num-traits = { version = "0.2", default-features = false }
num-bigint = { version = "0.4", default-features = false }
num-integer = { version = "0.1", default-features = false }
size-of = { version = "0.1.5", default-features = false }

# Optional
arbitrary = { version = "1.3", optional = true }
Expand Down
17 changes: 17 additions & 0 deletions crates/starknet-types-core/src/felt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use num_bigint::{BigInt, BigUint, Sign};
use num_integer::Integer;
use num_traits::{One, Zero};
pub use primitive_conversions::PrimitiveFromFeltError;
use size_of::SizeOf;

use lambdaworks_math::{
field::{
Expand All @@ -48,6 +49,10 @@ use lambdaworks_math::{
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Felt(pub(crate) FieldElement<Stark252PrimeField>);

impl SizeOf for Felt {
fn size_of_children(&self, _context: &mut size_of::Context) {}
}

#[derive(Debug)]
pub struct FromStrError(CreationError);

Expand Down Expand Up @@ -769,6 +774,7 @@ mod test {
use num_traits::Num;
use proptest::prelude::*;
use regex::Regex;
use size_of::TotalSize;

#[test]
fn test_debug_format() {
Expand Down Expand Up @@ -1330,4 +1336,15 @@ mod test {
assert_eq!(one, Felt::ONE);
assert_eq!(zero, Felt::ZERO);
}

#[test]
fn felt_size_of() {
assert_eq!(Felt::ZERO.size_of(), TotalSize::total(32));
assert_eq!(Felt::ONE.size_of(), TotalSize::total(32));
assert_eq!(
Felt(FieldElement::from(1600000000)).size_of(),
TotalSize::total(32)
);
assert_eq!(Felt::MAX.size_of(), TotalSize::total(32));
}
}