pub struct FileSystem<'ctx> { /* private fields */ }Expand description
RAII wrapper for a duckdb_file_system.
Automatically destroyed when dropped.
§Lifetime
duckdb_client_context_get_file_system does not hand out an owned file
system: its wrapper holds a reference to the connection’s client file
system, which the connection’s ClientContext owns and frees when the
connection closes. Using the handle after that is a heap use-after-free, so
a FileSystem borrows the ClientContext it came from for 'ctx.
use quack_rs::client_context::ClientContext;
use quack_rs::file_system::{FileOpenOptions, FileSystem};
fn demo(ctx: ClientContext) {
let fs = FileSystem::from_client_context(&ctx).unwrap();
drop(ctx); // error[E0505]: cannot move out of `ctx` because it is borrowed
let _ = fs.open(c"data.csv", &FileOpenOptions::read_only());
}FileHandles opened through it borrow it in turn, so a handle cannot
outlive the file system, the client context, or — through the context’s
contract — the connection and database behind them.
Implementations§
Source§impl<'ctx> FileSystem<'ctx>
impl<'ctx> FileSystem<'ctx>
Sourcepub fn from_client_context(context: &'ctx ClientContext) -> Option<Self>
pub fn from_client_context(context: &'ctx ClientContext) -> Option<Self>
Obtains the file system associated with a ClientContext.
The result borrows context; see the type-level docs for why.
Returns None if DuckDB does not provide one.
Sourcepub const unsafe fn from_raw(fs: duckdb_file_system) -> Self
pub const unsafe fn from_raw(fs: duckdb_file_system) -> Self
Wraps a raw duckdb_file_system handle, taking ownership.
§Safety
fs must be a valid, non-null duckdb_file_system handle that the caller
no longer manages, and the connection whose client context it was
obtained from must stay open for all of 'ctx — the handle refers to
that connection’s file system, which is freed when it closes.
Sourcepub fn open(
&self,
path: &CStr,
options: &FileOpenOptions,
) -> Result<FileHandle<'_>, ErrorData>
pub fn open( &self, path: &CStr, options: &FileOpenOptions, ) -> Result<FileHandle<'_>, ErrorData>
Opens path with the given options.
The handle borrows this file system; see FileHandle.
§Errors
Returns the structured ErrorData if the file cannot be opened.
Sourcepub fn error_data(&self) -> ErrorData
pub fn error_data(&self) -> ErrorData
Returns the structured error from the most recent failed operation.