From 7aab31646d03a0eed3f0d0ed420d48eb1f81497b Mon Sep 17 00:00:00 2001 From: glihm Date: Mon, 2 Dec 2024 10:24:16 -0600 Subject: [PATCH] docs: add missing documentation on types --- starknet-core/src/types/byte_array.rs | 10 +++++++++- starknet-core/src/types/bytes_31.rs | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/starknet-core/src/types/byte_array.rs b/starknet-core/src/types/byte_array.rs index fd7e85f7..e2cd4328 100644 --- a/starknet-core/src/types/byte_array.rs +++ b/starknet-core/src/types/byte_array.rs @@ -1,5 +1,5 @@ //! Support for [`String`] compatibility with Cairo `ByteArray`. -//! [https://github.com/starkware-libs/cairo/blob/f3af4cb8dbe9acecaf71cfbc604df3d1e41fe45a/corelib/src/byte_array.cairo]. +//! . //! //! The basic concept of this `ByteArray` is relying on a string being //! represented as an array of bytes packed by 31 bytes ([`Bytes31`]) in a [`Felt`]. @@ -16,10 +16,18 @@ use crate::types::{Bytes31, Felt}; const MAX_WORD_LEN: usize = 31; +/// A struct representing a Cairo `ByteArray`. #[derive(Debug, Clone, Eq, PartialEq, Default)] pub struct ByteArray { + /// An array of full "words" of 31 bytes each. + /// The first byte of each word in the byte array is the most significant byte in the word. pub data: Vec, + /// A `felt252` that actually represents a `bytes31`, with less than 31 bytes. + /// It is represented as a `felt252` to improve performance of building the byte array. + /// The first byte is the most significant byte among the `pending_word_len` bytes in the word. pub pending_word: Bytes31, + /// The number of bytes in `pending_word`. + /// Its value should be in the range [0, 30]. pub pending_word_len: usize, } diff --git a/starknet-core/src/types/bytes_31.rs b/starknet-core/src/types/bytes_31.rs index f0f78a22..5aba8242 100644 --- a/starknet-core/src/types/bytes_31.rs +++ b/starknet-core/src/types/bytes_31.rs @@ -1,5 +1,5 @@ //! Support for `Bytes31` Cairo primitive. -//! [https://github.com/starkware-libs/cairo/blob/main/corelib/src/bytes_31.cairo]. +//! . //! //! This type is mostly used internally for [`crate::types::ByteArray`] internal logic. use alloc::{ @@ -59,6 +59,7 @@ impl Bytes31 { String::from_utf8(buffer) } + /// Converts a hex string to a [`Bytes31`]. pub fn from_hex(hex: &str) -> Result { Ok(Self(Felt::from_hex(hex)?)) }