@@ -32,7 +32,7 @@ pub struct DatabaseOptions {
3232 create_new : bool ,
3333 wipe : bool ,
3434 meta_path : Option < PathBuf > ,
35- max_pages : u32 ,
35+ max_pages : Option < NonZero < u32 > > ,
3636 num_threads : Option < NonZero < usize > > ,
3737}
3838
@@ -86,8 +86,8 @@ impl DatabaseOptions {
8686 }
8787
8888 /// Sets the maximum number of pages that can be allocated.
89- pub fn max_pages ( & mut self , max_pages : u32 ) -> & mut Self {
90- self . max_pages = max_pages;
89+ pub fn max_pages ( & mut self , max_pages : NonZero < u32 > ) -> & mut Self {
90+ self . max_pages = Some ( max_pages) ;
9191 self
9292 }
9393
@@ -151,13 +151,18 @@ impl Database {
151151 }
152152
153153 let page_count = meta_manager. active_slot ( ) . page_count ( ) ;
154- let page_manager = PageManager :: options ( )
154+
155+ let mut page_manager_options = PageManager :: options ( ) ;
156+ page_manager_options
155157 . create ( opts. create )
156158 . create_new ( opts. create_new )
157159 . wipe ( opts. wipe )
158- . page_count ( page_count)
159- . open ( db_path)
160- . map_err ( OpenError :: PageError ) ?;
160+ . page_count ( page_count) ;
161+ if let Some ( max_pages) = opts. max_pages {
162+ page_manager_options. max_pages ( max_pages. get ( ) ) ;
163+ }
164+
165+ let page_manager = page_manager_options. open ( db_path) . map_err ( OpenError :: PageError ) ?;
161166
162167 let thread_pool = threadpool:: builder ( )
163168 . num_threads ( opts. num_threads . map ( NonZero :: get) . unwrap_or ( 0 ) )
0 commit comments