Trait sqlite_vfs::Vfs
source · [−]pub trait Vfs {
type File: File;
fn open(&self, path: &Path, opts: OpenOptions) -> Result<Self::File, Error>;
fn delete(&self, path: &Path) -> Result<(), Error>;
fn exists(&self, path: &Path) -> Result<bool, Error>;
fn access(&self, _path: &Path, _write: bool) -> Result<bool, Error> { ... }
}
Expand description
A virtual file system for SQLite.
Example
This example uses std::fs to to persist the database to disk.
struct FsVfs;
impl Vfs for FsVfs {
type File = fs::File;
fn open(&self, path: &Path, opts: OpenOptions) -> Result<Self::File, std::io::Error> {
let mut o = fs::OpenOptions::new();
o.read(true).write(opts.access != OpenAccess::Read);
match opts.access {
OpenAccess::Create => {
o.create(true);
}
OpenAccess::CreateNew => {
o.create_new(true);
}
_ => {}
}
let f = o.open(path)?;
Ok(f)
}
fn delete(&self, path: &std::path::Path) -> Result<(), std::io::Error> {
std::fs::remove_file(path)
}
fn exists(&self, path: &Path) -> Result<bool, std::io::Error> {
Ok(path.is_file())
}
}
Associated Types
Required methods
Open the database object (of type opts.kind
) at path
.