Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 99dad52

Browse files
Add impls for Arc<T>
1 parent f528afc commit 99dad52

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

merde_core/src/deserialize.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{
66
hash::{BuildHasher, Hash},
77
marker::PhantomData,
88
pin::Pin,
9+
sync::Arc,
910
};
1011

1112
use crate::{
@@ -486,6 +487,13 @@ impl<'s, T: Deserialize<'s>> Deserialize<'s> for Vec<T> {
486487
}
487488
}
488489

490+
impl<'s, T: Deserialize<'s>> Deserialize<'s> for Arc<T> {
491+
async fn deserialize(de: &mut dyn DynDeserializer<'s>) -> Result<Self, MerdeError<'s>> {
492+
let value: T = T::deserialize(de).await?;
493+
Ok(Arc::new(value))
494+
}
495+
}
496+
489497
impl<'s, K, V, S> Deserialize<'s> for HashMap<K, V, S>
490498
where
491499
K: Deserialize<'s> + Eq + Hash,

merde_core/src/into_static.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::collections::HashSet;
44
use std::collections::VecDeque;
55
use std::hash::BuildHasher;
66
use std::hash::Hash;
7+
use std::sync::Arc;
78

89
use crate::Event;
910

@@ -114,6 +115,15 @@ impl<T: IntoStatic> IntoStatic for Vec<T> {
114115
}
115116
}
116117

118+
impl<T: IntoStatic + Clone> IntoStatic for Arc<T> {
119+
type Output = Arc<T::Output>;
120+
121+
fn into_static(self) -> Self::Output {
122+
let t: T = (*self).clone();
123+
Arc::new(t.into_static())
124+
}
125+
}
126+
117127
impl<K, V, S> IntoStatic for HashMap<K, V, S>
118128
where
119129
S: BuildHasher + Default + 'static,

merde_core/src/serialize.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use std::{borrow::Cow, collections::HashMap, future::Future, hash::BuildHasher, pin::Pin};
1+
use std::{
2+
borrow::Cow, collections::HashMap, future::Future, hash::BuildHasher, pin::Pin, sync::Arc,
3+
};
24

35
use crate::{
46
metastack::MetastackExt, Array, ArrayStart, CowBytes, CowStr, Event, Map, MapStart, MerdeError,
@@ -211,6 +213,15 @@ impl<T: Serialize> Serialize for Vec<T> {
211213
}
212214
}
213215

216+
impl<T: Serialize> Serialize for Arc<T> {
217+
async fn serialize<'se>(
218+
&'se self,
219+
serializer: &'se mut dyn DynSerializer,
220+
) -> Result<(), MerdeError<'static>> {
221+
(**self).serialize(serializer).await
222+
}
223+
}
224+
214225
impl<K: Serialize, V: Serialize, BH: BuildHasher> Serialize for HashMap<K, V, BH> {
215226
async fn serialize<'fut>(
216227
&'fut self,

merde_core/src/with_lifetime.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{
22
borrow::Cow,
33
collections::{HashMap, HashSet, VecDeque},
4+
sync::Arc,
45
};
56

67
use crate::{CowStr, Value};
@@ -84,6 +85,13 @@ where
8485
type Lifetimed = Vec<T::Lifetimed>;
8586
}
8687

88+
impl<'s, T> WithLifetime<'s> for Arc<T>
89+
where
90+
T: WithLifetime<'s>,
91+
{
92+
type Lifetimed = Arc<T::Lifetimed>;
93+
}
94+
8795
impl<'s, T> WithLifetime<'s> for VecDeque<T>
8896
where
8997
T: WithLifetime<'s>,

0 commit comments

Comments
 (0)