Skip to content

Commit 3ce8d2d

Browse files
committed
feat: implement RadonOpCodes::MapStringify
1 parent 73d49e7 commit 3ce8d2d

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

rad/src/operators/map.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ pub fn values(input: &RadonMap) -> RadonArray {
8080
let v: Vec<RadonTypes> = input.value().values().cloned().collect();
8181
RadonArray::from(v)
8282
}
83+
pub fn stringify(input: &RadonMap) -> Result<RadonString, RadError> {
84+
let json_string = serde_json::to_string(&input.value())
85+
.map_err(|_| RadError::Decode {
86+
from: "RadonMap",
87+
to: "RadonString"
88+
})?;
89+
Ok(RadonString::from(json_string))
90+
}
8391

8492
/// This module was introduced for encapsulating the interim legacy logic before WIP-0024 is
8593
/// introduced, for the sake of maintainability.

rad/src/operators/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub enum RadonOpCodes {
8484
FloatTruncate = 0x5D,
8585
///////////////////////////////////////////////////////////////////////
8686
// Map operator codes (start at 0x60)
87-
// MapEntries = 0x60,
87+
MapStringify = 0x60,
8888
MapGetArray = 0x61,
8989
MapGetBoolean = 0x62,
9090
MapGetBytes = 0x63,

rad/src/types/map.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ impl Operable for RadonMap {
161161
}
162162
(RadonOpCodes::MapKeys, None) => Ok(RadonTypes::from(map_operators::keys(self))),
163163
(RadonOpCodes::MapValues, None) => Ok(RadonTypes::from(map_operators::values(self))),
164+
(RadonOpCodes::MapStringify, None) => map_operators::stringify(self).map(RadonTypes::from),
164165
(op_code, args) => Err(RadError::UnsupportedOperator {
165166
input_type: RADON_MAP_TYPE_NAME.to_string(),
166167
operator: op_code.to_string(),

0 commit comments

Comments
 (0)