-
-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rspack_cacheable):
as
attr support use with dyn trait (#8535)
* feat(rspack_cacheable): `as` attr support use with dyn trait * fix: ci
- Loading branch information
1 parent
27e8d88
commit c1e8f11
Showing
15 changed files
with
160 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 49 additions & 21 deletions
70
crates/rspack_cacheable_test/tests/macro/cacheable/as_attr.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,62 @@ | ||
use rspack_cacheable::{ | ||
cacheable, from_bytes, to_bytes, | ||
with::{AsTuple2, Inline}, | ||
cacheable, cacheable_dyn, from_bytes, to_bytes, | ||
with::{AsOption, AsTuple2, AsVec, Inline}, | ||
}; | ||
|
||
#[cacheable_dyn] | ||
trait Module {} | ||
|
||
#[cacheable] | ||
struct NormalModule { | ||
inner: String, | ||
} | ||
|
||
#[cacheable_dyn] | ||
impl Module for NormalModule {} | ||
|
||
#[cacheable] | ||
#[derive(Debug, PartialEq, Eq)] | ||
struct Person { | ||
name: String, | ||
content: (String, String), | ||
struct Data { | ||
block1: String, | ||
block2: Vec<(String, Option<String>)>, | ||
block3: Box<dyn Module>, | ||
} | ||
|
||
#[cacheable(as=Person)] | ||
struct PersonRef<'a> { | ||
#[rkyv(with=Inline)] | ||
name: &'a String, | ||
#[rkyv(with=AsTuple2<Inline, Inline>)] | ||
content: (&'a String, &'a String), | ||
#[cacheable(as=Data)] | ||
struct DataRef<'a> { | ||
#[cacheable(with=Inline)] | ||
block1: &'a String, | ||
#[cacheable(with=AsVec<AsTuple2<Inline, AsOption<Inline>>>)] | ||
block2: Vec<(&'a String, Option<&'a String>)>, | ||
#[allow(clippy::borrowed_box)] | ||
#[cacheable(with=Inline)] | ||
block3: &'a Box<dyn Module>, | ||
} | ||
|
||
#[test] | ||
#[cfg_attr(miri, ignore)] | ||
fn as_attr() { | ||
let a = Person { | ||
name: "abc".into(), | ||
content: ("a".into(), "b".into()), | ||
let a = Data { | ||
block1: "abc".into(), | ||
block2: vec![ | ||
("key1".into(), None), | ||
("key2".into(), Some("value2".into())), | ||
("key3".into(), Some("value3".into())), | ||
], | ||
block3: Box::new(NormalModule { | ||
inner: "inner".into(), | ||
}), | ||
}; | ||
let a_ref = PersonRef { | ||
name: &a.name, | ||
content: (&a.content.0, &a.content.1), | ||
let a_ref = DataRef { | ||
block1: &a.block1, | ||
block2: a | ||
.block2 | ||
.iter() | ||
.map(|(key, value)| (key, value.as_ref())) | ||
.collect(), | ||
block3: &a.block3, | ||
}; | ||
let bytes = to_bytes(&a_ref, &()).unwrap(); | ||
let deserialize_a: Person = from_bytes(&bytes, &()).unwrap(); | ||
assert_eq!(a, deserialize_a); | ||
let bytes = to_bytes(&a, &()).unwrap(); | ||
let bytes_ref = to_bytes(&a_ref, &()).unwrap(); | ||
assert_eq!(bytes, bytes_ref); | ||
from_bytes::<Data, ()>(&bytes, &()).unwrap(); | ||
} |
Oops, something went wrong.
c1e8f11
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Benchmark detail: Open
c1e8f11
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Ran ecosystem CI: Open