Skip to content

Commit c1e8f11

Browse files
authored
feat(rspack_cacheable): as attr support use with dyn trait (#8535)
* feat(rspack_cacheable): `as` attr support use with dyn trait * fix: ci
1 parent 27e8d88 commit c1e8f11

File tree

15 files changed

+160
-68
lines changed

15 files changed

+160
-68
lines changed

crates/rspack_cacheable/src/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ impl<'a> ContextGuard<'a> {
2020
Self { context }
2121
}
2222

23-
pub fn add_to_sharing<S: Sharing<SerializeError>>(
23+
pub fn add_to_sharing<S: Sharing<SerializeError> + ?Sized>(
2424
&self,
2525
sharing: &mut S,
2626
) -> Result<(), SerializeError> {
2727
sharing.start_sharing(CONTEXT_ADDR);
2828
sharing.finish_sharing(CONTEXT_ADDR, self as *const _ as usize)
2929
}
3030

31-
pub fn sharing_context<S: Sharing<SerializeError>>(
31+
pub fn sharing_context<S: Sharing<SerializeError> + ?Sized>(
3232
sharing: &'a mut S,
3333
) -> Result<&'a dyn Any, SerializeError> {
3434
match sharing.start_sharing(CONTEXT_ADDR) {
@@ -40,7 +40,7 @@ impl<'a> ContextGuard<'a> {
4040
}
4141
}
4242

43-
pub fn add_to_pooling<P: Pooling<DeserializeError>>(
43+
pub fn add_to_pooling<P: Pooling<DeserializeError> + ?Sized>(
4444
&self,
4545
pooling: &mut P,
4646
) -> Result<(), DeserializeError> {
@@ -51,7 +51,7 @@ impl<'a> ContextGuard<'a> {
5151
}
5252
}
5353

54-
pub fn pooling_context<P: Pooling<DeserializeError>>(
54+
pub fn pooling_context<P: Pooling<DeserializeError> + ?Sized>(
5555
pooling: &'a mut P,
5656
) -> Result<&'a dyn Any, DeserializeError> {
5757
match pooling.start_pooling(CONTEXT_ADDR) {

crates/rspack_cacheable/src/with/as.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ where
4343
impl<T, A, S> SerializeWith<T, S> for As<A>
4444
where
4545
A: AsConverter<T> + Archive + Serialize<S>,
46-
S: Fallible<Error = SerializeError> + Sharing,
46+
S: Fallible<Error = SerializeError> + Sharing + ?Sized,
4747
{
4848
#[inline]
4949
fn serialize_with(field: &T, serializer: &mut S) -> Result<Self::Resolver, SerializeError> {
@@ -60,7 +60,7 @@ impl<T, A, D> DeserializeWith<Archived<A>, T, D> for As<A>
6060
where
6161
A: AsConverter<T> + Archive,
6262
A::Archived: Deserialize<A, D>,
63-
D: Fallible<Error = DeserializeError> + Pooling,
63+
D: Fallible<Error = DeserializeError> + Pooling + ?Sized,
6464
{
6565
#[inline]
6666
fn deserialize_with(field: &Archived<A>, de: &mut D) -> Result<T, DeserializeError> {

crates/rspack_cacheable/src/with/as_cacheable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl<T: Archive> ArchiveWith<T> for AsCacheable {
2020
impl<T, S> SerializeWith<T, S> for AsCacheable
2121
where
2222
T: Archive + Serialize<S>,
23-
S: ?Sized + Fallible,
23+
S: Fallible + ?Sized,
2424
{
2525
#[inline]
2626
fn serialize_with(field: &T, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
@@ -32,7 +32,7 @@ impl<T, D> DeserializeWith<Archived<T>, T, D> for AsCacheable
3232
where
3333
T: Archive,
3434
T::Archived: Deserialize<T, D>,
35-
D: ?Sized + Fallible,
35+
D: Fallible + ?Sized,
3636
{
3737
#[inline]
3838
fn deserialize_with(field: &Archived<T>, de: &mut D) -> Result<T, D::Error> {

crates/rspack_cacheable/src/with/as_inner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<T, A, O, D> DeserializeWith<A::Archived, T, D> for AsInner<A>
4848
where
4949
T: AsInnerConverter<Inner = O>,
5050
A: ArchiveWith<O> + DeserializeWith<A::Archived, O, D>,
51-
D: ?Sized + Fallible,
51+
D: Fallible + ?Sized,
5252
{
5353
fn deserialize_with(field: &A::Archived, d: &mut D) -> Result<T, D::Error> {
5454
Ok(T::from_inner(A::deserialize_with(field, d)?))

crates/rspack_cacheable/src/with/as_map.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ where
5757
}
5858
}
5959

60-
impl<WK, WV, K, V, S: Fallible + ?Sized> Serialize<S> for Entry<&'_ K, &'_ V, WK, WV>
60+
impl<WK, WV, K, V, S> Serialize<S> for Entry<&'_ K, &'_ V, WK, WV>
6161
where
6262
WK: SerializeWith<K, S>,
6363
WV: SerializeWith<V, S>,
64+
S: Fallible + ?Sized,
6465
{
6566
#[inline]
6667
fn serialize(&self, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
@@ -90,7 +91,7 @@ where
9091
T: AsMapConverter<Key = K, Value = V>,
9192
WK: ArchiveWith<K>,
9293
WV: ArchiveWith<V>,
93-
S: Fallible + ?Sized + Allocator + Writer,
94+
S: Fallible + Allocator + Writer + ?Sized,
9495
for<'a> Entry<&'a K, &'a V, WK, WV>: Serialize<S>,
9596
{
9697
fn serialize_with(field: &T, s: &mut S) -> Result<Self::Resolver, S::Error> {

crates/rspack_cacheable/src/with/as_ref_str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ where
3131
impl<T, S> SerializeWith<T, S> for AsRefStr
3232
where
3333
T: AsRefStrConverter,
34-
S: ?Sized + Fallible + Writer,
34+
S: Fallible + Writer + ?Sized,
3535
S::Error: Source,
3636
{
3737
#[inline]
@@ -43,7 +43,7 @@ where
4343
impl<T, D> DeserializeWith<ArchivedString, T, D> for AsRefStr
4444
where
4545
T: AsRefStrConverter,
46-
D: ?Sized + Fallible,
46+
D: Fallible + ?Sized,
4747
{
4848
#[inline]
4949
fn deserialize_with(field: &ArchivedString, _: &mut D) -> Result<T, D::Error> {

crates/rspack_cacheable/src/with/as_string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ where
3939
impl<T, S> SerializeWith<T, S> for AsString
4040
where
4141
T: AsStringConverter,
42-
S: Fallible<Error = SerializeError> + Writer,
42+
S: Fallible<Error = SerializeError> + Writer + ?Sized,
4343
{
4444
#[inline]
4545
fn serialize_with(field: &T, serializer: &mut S) -> Result<Self::Resolver, SerializeError> {
@@ -52,7 +52,7 @@ where
5252
impl<T, D> DeserializeWith<ArchivedString, T, D> for AsString
5353
where
5454
T: AsStringConverter,
55-
D: Fallible<Error = DeserializeError>,
55+
D: Fallible<Error = DeserializeError> + ?Sized,
5656
{
5757
#[inline]
5858
fn deserialize_with(field: &ArchivedString, _: &mut D) -> Result<T, DeserializeError> {

crates/rspack_cacheable/src/with/as_tuple2.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ where
3030
}
3131
}
3232

33-
impl<A, B, K, V, S: Fallible + ?Sized> SerializeWith<(K, V), S> for AsTuple2<A, B>
33+
impl<A, B, K, V, S> SerializeWith<(K, V), S> for AsTuple2<A, B>
3434
where
3535
A: SerializeWith<K, S>,
3636
B: SerializeWith<V, S>,
37+
S: Fallible + ?Sized,
3738
{
3839
#[inline]
3940
fn serialize_with(field: &(K, V), serializer: &mut S) -> Result<Self::Resolver, S::Error> {
@@ -49,7 +50,7 @@ impl<A, B, K, V, D> DeserializeWith<ArchivedTuple2<A::Archived, B::Archived>, (K
4950
where
5051
A: ArchiveWith<K> + DeserializeWith<A::Archived, K, D>,
5152
B: ArchiveWith<V> + DeserializeWith<B::Archived, V, D>,
52-
D: ?Sized + Fallible,
53+
D: Fallible + ?Sized,
5354
{
5455
fn deserialize_with(
5556
field: &ArchivedTuple2<A::Archived, B::Archived>,

crates/rspack_cacheable/src/with/as_tuple3.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ where
3434
}
3535
}
3636

37-
impl<A, B, C, K, V, H, S: Fallible + ?Sized> SerializeWith<(K, V, H), S> for AsTuple3<A, B, C>
37+
impl<A, B, C, K, V, H, S> SerializeWith<(K, V, H), S> for AsTuple3<A, B, C>
3838
where
3939
A: SerializeWith<K, S>,
4040
B: SerializeWith<V, S>,
4141
C: SerializeWith<H, S>,
42+
S: Fallible + ?Sized,
4243
{
4344
#[inline]
4445
fn serialize_with(field: &(K, V, H), serializer: &mut S) -> Result<Self::Resolver, S::Error> {
@@ -57,7 +58,7 @@ where
5758
A: ArchiveWith<K> + DeserializeWith<A::Archived, K, D>,
5859
B: ArchiveWith<V> + DeserializeWith<B::Archived, V, D>,
5960
C: ArchiveWith<H> + DeserializeWith<C::Archived, H, D>,
60-
D: ?Sized + Fallible,
61+
D: Fallible + ?Sized,
6162
{
6263
fn deserialize_with(
6364
field: &ArchivedTuple3<A::Archived, B::Archived, C::Archived>,

crates/rspack_cacheable/src/with/as_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ where
7979
impl<T, A, O, D> DeserializeWith<ArchivedVec<A::Archived>, T, D> for AsVec<A>
8080
where
8181
T: AsVecConverter<Item = O>,
82-
D: Fallible<Error = DeserializeError>,
82+
D: Fallible<Error = DeserializeError> + ?Sized,
8383
A: ArchiveWith<O> + DeserializeWith<A::Archived, O, D>,
8484
{
8585
fn deserialize_with(field: &ArchivedVec<A::Archived>, d: &mut D) -> Result<T, DeserializeError> {

0 commit comments

Comments
 (0)