@@ -37,7 +37,7 @@ pub struct PoolBuilder {
3737 flags : OpenFlags ,
3838 journal_mode : Option < JournalMode > ,
3939 vfs : Option < String > ,
40- num_conns : Option < NonZeroUsize > ,
40+ num_conns : Option < usize > ,
4141}
4242
4343impl PoolBuilder {
@@ -78,22 +78,16 @@ impl PoolBuilder {
7878
7979 /// Specify the number of sqlite connections to open as part of the pool.
8080 ///
81- /// Defaults to the number of logical CPUs of the current system.
81+ /// Defaults to the number of logical CPUs of the current system. Values
82+ /// less than `1` are clamped to `1`.
8283 ///
8384 /// ```
8485 /// use async_sqlite::PoolBuilder;
85- /// use std::num::NonZeroUsize;
8686 ///
87- /// let builder = PoolBuilder::new().num_conns(NonZeroUsize::new(2).unwrap() );
87+ /// let builder = PoolBuilder::new().num_conns(2 );
8888 /// ```
89- ///
90- /// ```compile_fail
91- /// use async_sqlite::PoolBuilder;
92- ///
93- /// PoolBuilder::new().num_conns(0);
94- /// ```
95- pub fn num_conns ( mut self , num_conns : NonZeroUsize ) -> Self {
96- self . num_conns = Some ( num_conns) ;
89+ pub fn num_conns ( mut self , num_conns : usize ) -> Self {
90+ self . num_conns = Some ( num_conns. max ( 1 ) ) ;
9791 self
9892 }
9993
@@ -110,7 +104,7 @@ impl PoolBuilder {
110104 /// ```
111105 pub async fn open ( self ) -> Result < Pool , Error > {
112106 let num_conns = self . get_num_conns ( ) ;
113- let opens = ( 0 ..num_conns. get ( ) ) . map ( |_| {
107+ let opens = ( 0 ..num_conns) . map ( |_| {
114108 ClientBuilder {
115109 path : self . path . clone ( ) ,
116110 flags : self . flags ,
@@ -145,7 +139,7 @@ impl PoolBuilder {
145139 /// ```
146140 pub fn open_blocking ( self ) -> Result < Pool , Error > {
147141 let num_conns = self . get_num_conns ( ) ;
148- let clients = ( 0 ..num_conns. get ( ) )
142+ let clients = ( 0 ..num_conns)
149143 . map ( |_| {
150144 ClientBuilder {
151145 path : self . path . clone ( ) ,
@@ -164,8 +158,8 @@ impl PoolBuilder {
164158 } )
165159 }
166160
167- fn get_num_conns ( & self ) -> NonZeroUsize {
168- self . num_conns . unwrap_or_else ( || {
161+ fn get_num_conns ( & self ) -> usize {
162+ . unwrap_or_else ( || available_parallelism ( ) . unwrap_or_else ( |_| NonZeroUsize :: new ( 1 ) . unwrap ( ) ) . into ( ) )
169163 available_parallelism ( ) . unwrap_or_else ( |_| NonZeroUsize :: new ( 1 ) . unwrap ( ) )
170164 } )
171165 }
0 commit comments