11use crate :: bytecode:: * ;
22use crate :: marshal:: { self , Read , ReadBorrowed , Write } ;
33
4- /// A frozen module. Holds a frozen code object and whether it is part of a package.
5- /// The `origname` type is generic to allow either static names (runtime) or
6- /// borrowed/owned names during compile-time freezing.
4+ /// A frozen module. Holds a frozen code object and whether it is part of a package
75#[ derive( Copy , Clone ) ]
8- pub struct FrozenModule < B = & ' static [ u8 ] , N = & ' static str > {
6+ pub struct FrozenModule < B = & ' static [ u8 ] > {
97 pub code : FrozenCodeObject < B > ,
108 pub package : bool ,
11- pub origname : N ,
129}
1310
1411#[ derive( Copy , Clone ) ]
@@ -58,7 +55,7 @@ impl<B: AsRef<[u8]> + ?Sized> FrozenLib<B> {
5855}
5956
6057impl < ' a , B : AsRef < [ u8 ] > + ?Sized > IntoIterator for & ' a FrozenLib < B > {
61- type Item = ( & ' a str , FrozenModule < & ' a [ u8 ] , & ' a str > ) ;
58+ type Item = ( & ' a str , FrozenModule < & ' a [ u8 ] > ) ;
6259 type IntoIter = FrozenModulesIter < ' a > ;
6360
6461 fn into_iter ( self ) -> Self :: IntoIter {
@@ -72,7 +69,7 @@ pub struct FrozenModulesIter<'a> {
7269}
7370
7471impl < ' a > Iterator for FrozenModulesIter < ' a > {
75- type Item = ( & ' a str , FrozenModule < & ' a [ u8 ] , & ' a str > ) ;
72+ type Item = ( & ' a str , FrozenModule < & ' a [ u8 ] > ) ;
7673
7774 fn next ( & mut self ) -> Option < Self :: Item > {
7875 if self . remaining > 0 {
@@ -93,30 +90,21 @@ impl ExactSizeIterator for FrozenModulesIter<'_> {}
9390
9491fn read_entry < ' a > (
9592 rdr : & mut & ' a [ u8 ] ,
96- ) -> Result < ( & ' a str , FrozenModule < & ' a [ u8 ] , & ' a str > ) , marshal:: MarshalError > {
93+ ) -> Result < ( & ' a str , FrozenModule < & ' a [ u8 ] > ) , marshal:: MarshalError > {
9794 let len = rdr. read_u32 ( ) ?;
9895 let name = rdr. read_str_borrow ( len) ?;
9996 let len = rdr. read_u32 ( ) ?;
10097 let code_slice = rdr. read_slice_borrow ( len) ?;
10198 let code = FrozenCodeObject { bytes : code_slice } ;
10299 let package = rdr. read_u8 ( ) ? != 0 ;
103- let len = rdr. read_u32 ( ) ?;
104- let origname = rdr. read_str_borrow ( len) ?;
105- Ok ( (
106- name,
107- FrozenModule {
108- code,
109- package,
110- origname,
111- } ,
112- ) )
100+ Ok ( ( name, FrozenModule { code, package } ) )
113101}
114102
115103impl FrozenLib < Vec < u8 > > {
116104 /// Encode the given iterator of frozen modules into a compressed vector of bytes
117- pub fn encode < ' a , I , B : AsRef < [ u8 ] > , N : AsRef < str > > ( lib : I ) -> Self
105+ pub fn encode < ' a , I , B : AsRef < [ u8 ] > > ( lib : I ) -> Self
118106 where
119- I : IntoIterator < Item = ( & ' a str , FrozenModule < B , N > ) , IntoIter : ExactSizeIterator + Clone > ,
107+ I : IntoIterator < Item = ( & ' a str , FrozenModule < B > ) , IntoIter : ExactSizeIterator + Clone > ,
120108 {
121109 let iter = lib. into_iter ( ) ;
122110 let mut bytes = Vec :: new ( ) ;
@@ -125,23 +113,18 @@ impl FrozenLib<Vec<u8>> {
125113 }
126114}
127115
128- fn write_lib < ' a , B : AsRef < [ u8 ] > , N : AsRef < str > > (
116+ fn write_lib < ' a , B : AsRef < [ u8 ] > > (
129117 buf : & mut Vec < u8 > ,
130- lib : impl ExactSizeIterator < Item = ( & ' a str , FrozenModule < B , N > ) > ,
118+ lib : impl ExactSizeIterator < Item = ( & ' a str , FrozenModule < B > ) > ,
131119) {
132120 marshal:: write_len ( buf, lib. len ( ) ) ;
133121 for ( name, module) in lib {
134122 write_entry ( buf, name, module) ;
135123 }
136124}
137125
138- fn write_entry < N : AsRef < str > > (
139- buf : & mut Vec < u8 > ,
140- name : & str ,
141- module : FrozenModule < impl AsRef < [ u8 ] > , N > ,
142- ) {
126+ fn write_entry ( buf : & mut Vec < u8 > , name : & str , module : FrozenModule < impl AsRef < [ u8 ] > > ) {
143127 marshal:: write_vec ( buf, name. as_bytes ( ) ) ;
144128 marshal:: write_vec ( buf, module. code . bytes . as_ref ( ) ) ;
145129 buf. write_u8 ( module. package as u8 ) ;
146- marshal:: write_vec ( buf, module. origname . as_ref ( ) . as_bytes ( ) ) ;
147130}
0 commit comments