|
1 | 1 | use alloc::string::{String, ToString}; |
2 | | -use wasm_bindgen::{prelude::*, throw_str}; |
| 2 | +use wasm_bindgen::prelude::*; |
3 | 3 |
|
4 | 4 | use dwn_rs_core::{ |
5 | 5 | filters::{FilterKey, FilterSet, Filters, ValueFilter}, |
@@ -50,44 +50,42 @@ impl From<Filter> for Filters { |
50 | 50 |
|
51 | 51 | impl From<IndexMap> for (MapValue, MapValue) { |
52 | 52 | fn from(value: IndexMap) -> Self { |
53 | | - match serde_wasm_bindgen::from_value::<MapValue>(value.into()) { |
54 | | - Ok(m) => m.into_iter().fold( |
55 | | - (MapValue::new(), MapValue::new()), |
56 | | - |(mut indexes, mut tags), (k, v)| { |
57 | | - if let Some(tag) = k.strip_prefix("tag.") { |
58 | | - tags.insert(tag.to_string(), v); |
59 | | - } else { |
60 | | - indexes.insert(k, v); |
61 | | - } |
| 53 | + let m = serde_wasm_bindgen::from_value::<MapValue>(value.into()) |
| 54 | + .expect_throw("unable to deserialize indexes"); |
62 | 55 |
|
63 | | - (indexes, tags) |
64 | | - }, |
65 | | - ), |
66 | | - Err(e) => throw_str(&format!("unable to deserialize indexes: {:?}", e)), |
67 | | - } |
| 56 | + m.into_iter().fold( |
| 57 | + (MapValue::new(), MapValue::new()), |
| 58 | + |(mut indexes, mut tags), (k, v)| { |
| 59 | + if let Some(tag) = k.strip_prefix("tag.") { |
| 60 | + tags.insert(tag.to_string(), v); |
| 61 | + } else { |
| 62 | + indexes.insert(k, v); |
| 63 | + } |
| 64 | + |
| 65 | + (indexes, tags) |
| 66 | + }, |
| 67 | + ) |
68 | 68 | } |
69 | 69 | } |
70 | 70 |
|
71 | 71 | impl From<IndexMap> for MapValue { |
72 | 72 | fn from(value: IndexMap) -> Self { |
73 | | - match serde_wasm_bindgen::from_value::<MapValue>(value.into()) { |
74 | | - Ok(m) => m, |
75 | | - Err(e) => throw_str(&format!("unable to deserialize indexes: {:?}", e)), |
76 | | - } |
| 73 | + serde_wasm_bindgen::from_value::<MapValue>(value.into()) |
| 74 | + .expect_throw("unable to deserialize indexes") |
77 | 75 | } |
78 | 76 | } |
79 | 77 |
|
80 | 78 | impl From<MapValue> for IndexMap { |
81 | 79 | fn from(value: MapValue) -> Self { |
82 | | - match value.serialize(&crate::ser::serializer()) { |
83 | | - Ok(m) => m.into(), |
84 | | - Err(e) => throw_str(&format!("unable to serialize indexes: {:?}", e)), |
85 | | - } |
| 80 | + value |
| 81 | + .serialize(&crate::ser::serializer()) |
| 82 | + .expect_throw("unable to serialize indexes") |
| 83 | + .into() |
86 | 84 | } |
87 | 85 | } |
88 | 86 |
|
89 | | -impl std::fmt::Debug for IndexMap { |
90 | | - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 87 | +impl core::fmt::Debug for IndexMap { |
| 88 | + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
91 | 89 | f.debug_struct("IndexMap").finish() |
92 | 90 | } |
93 | 91 | } |
0 commit comments