File tree 2 files changed +31
-2
lines changed
2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 4
4
//! `swc_common`.
5
5
#![ allow( unused) ]
6
6
7
- use std:: any:: type_name;
7
+ use std:: { any:: type_name, mem } ;
8
8
9
9
use anyhow:: Error ;
10
10
use bytecheck:: CheckBytes ;
@@ -174,4 +174,27 @@ impl Serialized {
174
174
#[ derive( Archive , Deserialize , Serialize ) ]
175
175
#[ repr( transparent) ]
176
176
#[ archive_attr( repr( transparent) , derive( CheckBytes ) ) ]
177
- pub struct VersionedSerializable < T > ( #[ with( AsBox ) ] pub ( u32 , T ) ) ;
177
+ pub struct VersionedSerializable < T > ( #[ with( AsBox ) ] ( u32 , T ) ) ;
178
+
179
+ impl < T > VersionedSerializable < T > {
180
+ pub fn new ( value : T ) -> Self {
181
+ // TODO: we'll add compile time flag to augment schema version.
182
+ // User should not try to set version by themselves.
183
+ VersionedSerializable ( ( 1 , value) )
184
+ }
185
+
186
+ pub fn version ( & self ) -> u32 {
187
+ self . 0 . 0
188
+ }
189
+
190
+ pub fn inner ( & self ) -> & T {
191
+ & self . 0 . 1
192
+ }
193
+
194
+ pub fn take ( & mut self ) -> T
195
+ where
196
+ T : Default ,
197
+ {
198
+ mem:: take ( & mut self . 0 . 1 )
199
+ }
200
+ }
Original file line number Diff line number Diff line change @@ -14,6 +14,12 @@ pub enum Program {
14
14
Script ( Script ) ,
15
15
}
16
16
17
+ impl Default for Program {
18
+ fn default ( ) -> Self {
19
+ Program :: Module ( Module :: dummy ( ) )
20
+ }
21
+ }
22
+
17
23
#[ ast_node( "Module" ) ]
18
24
#[ derive( Eq , Hash , EqIgnoreSpan ) ]
19
25
pub struct Module {
You can’t perform that action at this time.
0 commit comments