Skip to content

Commit 7cea9b1

Browse files
committed
ndb: update open function to accept Path ref instead of str
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 6418672 commit 7cea9b1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

database/nostr-ndb/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#![allow(clippy::mutable_key_type)] // TODO: remove when possible. Needed to suppress false positive for async_trait
1111

1212
use std::borrow::Cow;
13+
use std::io::{Error, ErrorKind};
1314
use std::ops::{Deref, DerefMut};
15+
use std::path::Path;
1416

1517
pub extern crate nostr;
1618
pub extern crate nostr_database as database;
@@ -35,10 +37,14 @@ impl NdbDatabase {
3537
/// Open nostrdb
3638
pub fn open<P>(path: P) -> Result<Self, DatabaseError>
3739
where
38-
P: AsRef<str>,
40+
P: AsRef<Path>,
3941
{
40-
let path: &str = path.as_ref();
41-
let config = Config::new();
42+
let path: &Path = path.as_ref();
43+
let path: &str = path.to_str().ok_or_else(|| {
44+
DatabaseError::backend(Error::new(ErrorKind::InvalidInput, "path is not valid "))
45+
})?;
46+
47+
let config: Config = Config::new();
4248

4349
Ok(Self {
4450
db: Ndb::new(path, &config).map_err(DatabaseError::backend)?,

0 commit comments

Comments
 (0)