@@ -6,12 +6,7 @@ use std::{
66
77use anyhow:: Result ;
88use patricia_tree:: PatriciaMap ;
9- use serde:: {
10- Deserialize , Deserializer , Serialize , Serializer ,
11- de:: { MapAccess , Visitor } ,
12- ser:: SerializeMap ,
13- } ;
14- use serde_bytes:: { ByteBuf , Bytes } ;
9+ use serde:: { Deserialize , Serialize } ;
1510use turbo_rcstr:: RcStr ;
1611use turbo_tasks:: {
1712 NonLocalValue ,
@@ -29,7 +24,8 @@ use super::pattern::Pattern;
2924///
3025/// If the pattern does not have a wildcard character, it will only match the
3126/// exact string, and return the template as-is.
32- #[ derive( Clone ) ]
27+ #[ derive( Clone , Serialize , Deserialize ) ]
28+ #[ serde( transparent) ]
3329pub struct AliasMap < T > {
3430 map : PatriciaMap < BTreeMap < AliasKey , T > > ,
3531}
5551
5652impl < T > Eq for AliasMap < T > where T : Eq { }
5753
58- impl < T > Serialize for AliasMap < T >
59- where
60- T : Serialize ,
61- {
62- fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
63- where
64- S : Serializer ,
65- {
66- let mut map = serializer. serialize_map ( Some ( self . map . len ( ) ) ) ?;
67- for ( prefix, value) in self . map . iter ( ) {
68- let key = ByteBuf :: from ( prefix) ;
69- map. serialize_entry ( & key, value) ?;
70- }
71- map. end ( )
72- }
73- }
74-
75- struct AliasMapVisitor < T > {
76- marker : std:: marker:: PhantomData < T > ,
77- }
78-
79- impl < ' de , T > Visitor < ' de > for AliasMapVisitor < T >
80- where
81- T : Deserialize < ' de > ,
82- {
83- type Value = AliasMap < T > ;
84-
85- fn expecting ( & self , formatter : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
86- formatter. write_str ( "a map of alias patterns to templates" )
87- }
88-
89- fn visit_map < M > ( self , mut access : M ) -> Result < Self :: Value , M :: Error >
90- where
91- M : MapAccess < ' de > ,
92- {
93- let mut map = AliasMap :: new ( ) ;
94- while let Some ( ( key, value) ) = access. next_entry :: < & Bytes , _ > ( ) ? {
95- map. map . insert ( key, value) ;
96- }
97- Ok ( map)
98- }
99- }
100-
101- impl < ' a , T > Deserialize < ' a > for AliasMap < T >
102- where
103- T : Deserialize < ' a > ,
104- {
105- fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
106- where
107- D : Deserializer < ' a > ,
108- {
109- deserializer. deserialize_map ( AliasMapVisitor {
110- marker : std:: marker:: PhantomData ,
111- } )
112- }
113- }
114-
11554impl < T > TraceRawVcs for AliasMap < T >
11655where
11756 T : TraceRawVcs ,
@@ -392,7 +331,7 @@ impl<'a, T> IntoIterator for &'a AliasMap<T> {
392331///
393332/// [PATTERN_KEY_COMPARE]: https://nodejs.org/api/esm.html#resolver-algorithm-specification
394333pub struct AliasMapIntoIter < T > {
395- iter : patricia_tree:: map:: IntoIter < BTreeMap < AliasKey , T > > ,
334+ iter : patricia_tree:: map:: IntoIter < Vec < u8 > , BTreeMap < AliasKey , T > > ,
396335 current_prefix_iterator : Option < AliasMapIntoIterItem < T > > ,
397336}
398337
@@ -457,7 +396,7 @@ impl<T> Iterator for AliasMapIntoIter<T> {
457396///
458397/// [PATTERN_KEY_COMPARE]: https://nodejs.org/api/esm.html#resolver-algorithm-specification
459398pub struct AliasMapIter < ' a , T > {
460- iter : patricia_tree:: map:: Iter < ' a , BTreeMap < AliasKey , T > > ,
399+ iter : patricia_tree:: map:: Iter < ' a , Vec < u8 > , BTreeMap < AliasKey , T > > ,
461400 current_prefix_iterator : Option < AliasMapIterItem < ' a , T > > ,
462401}
463402
0 commit comments