Skip to content

Commit 96285c4

Browse files
committed
inline documentation
1 parent bce8f2f commit 96285c4

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/get_array.nr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::utils::cast_num_to_u32;
1212
impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let MaxNumValues: u32, let MaxKeyFields: u32> JSON<NumBytes, NumPackedFields, MaxNumTokens, MaxNumValues, MaxKeyFields> {
1313

1414
/**
15-
* @brief if the root JSON is an array, return its length
15+
* @brief Returns its length when the current root is an array; errors otherwise.
1616
**/
1717
pub fn get_length(self) -> u32 {
1818
assert(self.layer_type_of_root == ARRAY_LAYER, "can only get length of an array type");
@@ -23,7 +23,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
2323

2424
/**
2525
* @brief if the root JSON is an object, extract an array given by `key`
26-
* @description returns an Option<JSON> where, if the array exists, the JSON object will have the requested array as its root value
26+
* @description From an object root, returns Some(JSON) if key exists and is an array, None if key is missing; errors if key exists but is not an array, or if called when the current root is an array.
2727
**/
2828
pub fn get_array<let KeyBytes: u32>(self, key: [u8; KeyBytes]) -> Option<Self> {
2929
assert(self.layer_type_of_root != ARRAY_LAYER, "cannot extract array elements via a key");
@@ -49,7 +49,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
4949

5050
/**
5151
* @brief if the root JSON is an object, extract an array given by `key`
52-
* @description will revert if the array does not exist
52+
* @description From an object root, returns the array at key; errors otherwise.
5353
**/
5454
pub fn get_array_unchecked<let KeyBytes: u32>(self, key: [u8; KeyBytes]) -> Self {
5555
assert(self.layer_type_of_root != ARRAY_LAYER, "cannot extract array elements via a key");
@@ -67,7 +67,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
6767
}
6868

6969
/**
70-
* @brief same as `get_array` for where the key length may be less than KeyBytes
70+
* @brief Same as `get_array`, but the key can be variable-length up to `KeyBytes`.
7171
**/
7272
pub fn get_array_var<let KeyBytes: u32>(self, key: BoundedVec<u8, KeyBytes>) -> Option<Self> {
7373
assert(self.layer_type_of_root != ARRAY_LAYER, "cannot extract array elements via a key");
@@ -96,7 +96,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
9696
}
9797

9898
/**
99-
* @brief same as `get_array_unchecked` for where the key length may be less than KeyBytes
99+
* @brief Same as `get_array_unchecked`, but with a variable-length key.
100100
**/
101101
pub fn get_array_unchecked_var<let KeyBytes: u32>(self, key: BoundedVec<u8, KeyBytes>) -> Self {
102102
assert(self.layer_type_of_root != ARRAY_LAYER, "cannot extract array elements via a key");
@@ -115,7 +115,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
115115

116116
/**
117117
* @brief if the root JSON is an array, extract an array given by the position of the target in the source array
118-
* @description returns an Option<JSON> where, if the array exists, the JSON object will have the requested array as its root value
118+
* @description When the current root is an array, returns the nested array at `index` wrapped in `Option`. Returns `None` if `index` is out of bounds; errors if in-bounds but the element is not an array.
119119
**/
120120
pub fn get_array_from_array(self, array_index: Field) -> Option<Self> {
121121
assert(

src/get_object.nr

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use crate::utils::cast_num_to_u32;
1111
impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let MaxNumValues: u32, let MaxKeyFields: u32> JSON<NumBytes, NumPackedFields, MaxNumTokens, MaxNumValues, MaxKeyFields> {
1212

1313
/**
14-
* @brief if the root JSON is an object, extract a child object given by `key`
15-
* @description returns an Option<JSON> where, if the object exists, the JSON object will have the requested object as its root value
14+
* @brief From an object root, returns `Some(JSON)` if `key` exists and is an object, `None` if `key` is missing; errors if `key` exists but is not an object, or if called when the current root is an array.
1615
**/
1716
pub fn get_object<let KeyBytes: u32>(self, key: [u8; KeyBytes]) -> Option<Self> {
1817
assert(self.layer_type_of_root != ARRAY_LAYER, "cannot extract array elements via a key");
@@ -37,8 +36,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
3736
}
3837

3938
/**
40-
* @brief if the root JSON is an object, extract a child object given by `key`
41-
* @description will revert if the requested object does not exist
39+
* @brief From an object root, returns the object at `key`; errors otherwise.
4240
**/
4341
pub fn get_object_unchecked<let KeyBytes: u32>(self, key: [u8; KeyBytes]) -> Self {
4442
assert(self.layer_type_of_root != ARRAY_LAYER, "cannot extract array elements via a key");
@@ -58,7 +56,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
5856
}
5957

6058
/**
61-
* @brief same as `get_object` for where the key length may be less than KeyBytes
59+
* @brief Same as `get_object`, but the key can be variable-length up to `KeyBytes`.
6260
**/
6361
pub fn get_object_var<let KeyBytes: u32>(self, key: BoundedVec<u8, KeyBytes>) -> Option<Self> {
6462
assert(self.layer_type_of_root != ARRAY_LAYER, "cannot extract array elements via a key");
@@ -83,7 +81,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
8381
}
8482

8583
/**
86-
* @brief same as `get_object_unchecked` for where the key length may be less than KeyBytes
84+
* @brief Same as `get_object_unchecked`, but with a variable-length key.
8785
**/
8886
pub fn get_object_unchecked_var<let KeyBytes: u32>(
8987
self,
@@ -107,7 +105,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
107105

108106
/**
109107
* @brief if the root JSON is an array, extract an object given by the position of the target in the source array
110-
* @description returns an Option<JSON> where, if the object exists, the JSON object will have the requested object as its root value
108+
* @description When the current root is an array, returns the object at `index` wrapped in `Option`. Returns `None` if `index` is out of bounds; errors if in-bounds but the element is not an object.
111109
**/
112110
pub fn get_object_from_array(self, array_index: Field) -> Option<Self> {
113111
assert(
@@ -145,7 +143,7 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
145143

146144
/**
147145
* @brief if the root JSON is an array, extract an object given by the position of the target in the source array
148-
* @description will revert if the object does not exist
146+
* @description When the current root is an array, returns the object at `index`. Errors if `index` is out of bounds or the element is not an object.
149147
**/
150148
pub fn get_object_from_array_unchecked(self, array_index: Field) -> Self {
151149
assert(

0 commit comments

Comments
 (0)