Skip to content

Commit 63d5340

Browse files
committed
feat(dict): impl TryFrom<BTreeMap> for Dict
1 parent 5cdf8b2 commit 63d5340

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/dict/typed.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,36 @@ impl<K, V> std::fmt::Debug for Dict<K, V> {
9696
}
9797
}
9898

99+
impl<K, V, Q, T> TryFrom<BTreeMap<Q, T>> for Dict<K, V>
100+
where
101+
Q: Borrow<K>,
102+
T: Borrow<V>,
103+
K: StoreDictKey + Ord,
104+
V: Store,
105+
{
106+
type Error = Error;
107+
108+
#[inline]
109+
fn try_from(value: BTreeMap<Q, T>) -> Result<Self, Self::Error> {
110+
Self::try_from_btree(&value)
111+
}
112+
}
113+
114+
impl<K, V, Q, T> TryFrom<&'_ BTreeMap<Q, T>> for Dict<K, V>
115+
where
116+
Q: Borrow<K>,
117+
T: Borrow<V>,
118+
K: StoreDictKey + Ord,
119+
V: Store,
120+
{
121+
type Error = Error;
122+
123+
#[inline]
124+
fn try_from(value: &BTreeMap<Q, T>) -> Result<Self, Self::Error> {
125+
Self::try_from_btree(value)
126+
}
127+
}
128+
99129
impl<K, V> Dict<K, V> {
100130
/// Creates an empty dictionary
101131
pub const fn new() -> Self {

0 commit comments

Comments
 (0)