File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77## [ Unreleased]
88
99- Add ` descriptor::checksum::get_checksum_bytes ` method.
10+ - Change the interface of ` SqliteDatabase::new ` to accept any type that implement AsRef<Path >
1011
1112## [ v0.20.0] - [ v0.19.0]
1213
Original file line number Diff line number Diff line change 88// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
99// You may not use this file except in accordance with one or both of these
1010// licenses.
11+ use std:: path:: Path ;
12+ use std:: path:: PathBuf ;
1113
1214use bitcoin:: consensus:: encode:: { deserialize, serialize} ;
1315use bitcoin:: hash_types:: Txid ;
@@ -60,17 +62,20 @@ static MIGRATIONS: &[&str] = &[
6062#[ derive( Debug ) ]
6163pub struct SqliteDatabase {
6264 /// Path on the local filesystem to store the sqlite file
63- pub path : String ,
65+ pub path : PathBuf ,
6466 /// A rusqlite connection object to the sqlite database
6567 pub connection : Connection ,
6668}
6769
6870impl SqliteDatabase {
6971 /// Instantiate a new SqliteDatabase instance by creating a connection
7072 /// to the database stored at path
71- pub fn new ( path : String ) -> Self {
73+ pub fn new < T : AsRef < Path > > ( path : T ) -> Self {
7274 let connection = get_connection ( & path) . unwrap ( ) ;
73- SqliteDatabase { path, connection }
75+ SqliteDatabase {
76+ path : PathBuf :: from ( path. as_ref ( ) ) ,
77+ connection,
78+ }
7479 }
7580 fn insert_script_pubkey (
7681 & self ,
@@ -908,7 +913,7 @@ impl BatchDatabase for SqliteDatabase {
908913 }
909914}
910915
911- pub fn get_connection ( path : & str ) -> Result < Connection , Error > {
916+ pub fn get_connection < T : AsRef < Path > > ( path : & T ) -> Result < Connection , Error > {
912917 let connection = Connection :: open ( path) ?;
913918 migrate ( & connection) ?;
914919 Ok ( connection)
You can’t perform that action at this time.
0 commit comments