Skip to content

Commit 38c3198

Browse files
authored
display BlobTypes without quotes (#3731)
## Motivation Nicer output for `linera storage list_blob_ids` ## Proposal * Use the derived `Debug` to display `BlobType`s without quotes * Keep using `serde_json` for parsing (as opposed to importing `clap` or other crates) ## Test Plan CI
1 parent 239cd5d commit 38c3198

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

linera-base/src/identifiers.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,16 @@ pub enum BlobType {
183183

184184
impl Display for BlobType {
185185
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
186-
match serde_json::to_string(self) {
187-
Ok(s) => write!(f, "{}", s),
188-
Err(_) => Err(fmt::Error),
189-
}
186+
write!(f, "{:?}", self)
190187
}
191188
}
192189

193190
impl FromStr for BlobType {
194191
type Err = anyhow::Error;
195192

196193
fn from_str(s: &str) -> Result<Self, Self::Err> {
197-
serde_json::from_str(s).with_context(|| format!("Invalid BlobType: {}", s))
194+
serde_json::from_str(&format!("\"{s}\""))
195+
.with_context(|| format!("Invalid BlobType: {}", s))
198196
}
199197
}
200198

@@ -1124,7 +1122,7 @@ mod tests {
11241122

11251123
use assert_matches::assert_matches;
11261124

1127-
use super::{AccountOwner, ChainId};
1125+
use super::{AccountOwner, BlobType, ChainId};
11281126

11291127
/// Verifies that chain IDs that are explicitly used in some example and test scripts don't
11301128
/// change.
@@ -1152,6 +1150,15 @@ mod tests {
11521150
);
11531151
}
11541152

1153+
#[test]
1154+
fn blob_types() {
1155+
assert_eq!("ContractBytecode", BlobType::ContractBytecode.to_string());
1156+
assert_eq!(
1157+
BlobType::ContractBytecode,
1158+
BlobType::from_str("ContractBytecode").unwrap()
1159+
);
1160+
}
1161+
11551162
#[test]
11561163
fn addresses() {
11571164
assert_eq!(&AccountOwner::Reserved(0).to_string(), "0x00");

0 commit comments

Comments
 (0)