sqlite::open() takes an AsRef<Path> value

Now we can pass either a string or a Path to it, just like to
std::fs::File::open().
This commit is contained in:
Tomoki Aonuma 2015-06-19 13:10:22 +09:00
parent d155b7d33d
commit 423ecac84a
2 changed files with 3 additions and 3 deletions

View File

@ -14,10 +14,10 @@ pub struct Database<'l> {
impl<'l> Database<'l> {
/// Open a connection to a new or existing database.
pub fn open(path: &Path) -> Result<Database<'l>> {
pub fn open<P: AsRef<Path>>(path: P) -> Result<Database<'l>> {
let mut raw = 0 as *mut _;
unsafe {
success!(ffi::sqlite3_open_v2(path_to_c_str!(path), &mut raw,
success!(ffi::sqlite3_open_v2(path_to_c_str!(path.as_ref()), &mut raw,
ffi::SQLITE_OPEN_CREATE | ffi::SQLITE_OPEN_READWRITE,
0 as *const _));
}

View File

@ -99,7 +99,7 @@ pub type Result<T> = ::std::result::Result<T, Error>;
/// Open a connection to a new or existing database.
#[inline]
pub fn open<'l>(path: &std::path::Path) -> Result<Database<'l>> {
pub fn open<'l, P: std::convert::AsRef<std::path::Path>>(path: P) -> Result<Database<'l>> {
Database::open(path)
}