@@ -13,6 +13,7 @@ use crate::manifest::{MoveToml, Layout};
1313use std:: fs:: OpenOptions ;
1414use std:: io:: Write ;
1515
16+ /// Embedded move compiler.
1617#[ derive( Clone ) ]
1718pub struct Compiler < S : StateView + Clone > {
1819 loader : Option < Loader < StateViewLoader < S > > > ,
@@ -22,12 +23,14 @@ impl<S> Compiler<S>
2223where
2324 S : StateView + Clone ,
2425{
26+ /// Create move compiler.
2527 pub fn new ( view : S ) -> Compiler < S > {
2628 Compiler {
2729 loader : Some ( Loader :: new ( None , StateViewLoader :: new ( view) ) ) ,
2830 }
2931 }
3032
33+ /// Compile multiple sources.
3134 pub fn compile_source_map (
3235 & self ,
3336 source_map : HashMap < String , String > ,
6972 builder. verify ( text_source, units)
7073 }
7174
75+ /// Compiler source codes.
7276 pub fn compile ( & self , code : & str , address : Option < AccountAddress > ) -> Result < Vec < u8 > > {
7377 let mut source_map = HashMap :: new ( ) ;
7478 source_map. insert ( "source" . to_string ( ) , code. to_string ( ) ) ;
@@ -81,11 +85,14 @@ where
8185 }
8286}
8387
88+ /// Temp directory.
89+ /// Random temporary directory which will be removed when 'TempDir' drop.
8490pub struct TempDir {
8591 path : PathBuf ,
8692}
8793
8894impl TempDir {
95+ /// Create a new temporary directory.
8996 pub fn new ( ) -> Result < TempDir > {
9097 let dir = env:: temp_dir ( ) ;
9198 let mut rng = rand:: thread_rng ( ) ;
@@ -98,6 +105,7 @@ impl TempDir {
98105 Ok ( TempDir { path } )
99106 }
100107
108+ /// Returns the directory path.
101109 pub fn path ( & self ) -> & Path {
102110 & self . path
103111 }
@@ -116,11 +124,13 @@ impl Drop for TempDir {
116124 }
117125}
118126
127+ /// Compiler string with move source code.
119128pub fn compile ( code : & str , address : Option < AccountAddress > ) -> Result < Vec < u8 > > {
120129 let compiler = Compiler :: new ( ZeroStateView ) ;
121130 compiler. compile ( code, address)
122131}
123132
133+ /// State view mock.
124134#[ derive( Clone ) ]
125135struct ZeroStateView ;
126136
0 commit comments