Skip to main content

FileSystem

Struct FileSystem 

Source
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>

Source

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.

Source

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.

Source

pub const fn as_raw(&self) -> duckdb_file_system

Returns the raw handle.

Source

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.

Source

pub fn error_data(&self) -> ErrorData

Returns the structured error from the most recent failed operation.

Trait Implementations§

Source§

impl Debug for FileSystem<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for FileSystem<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'ctx> !Send for FileSystem<'ctx>

§

impl<'ctx> !Sync for FileSystem<'ctx>

§

impl<'ctx> Freeze for FileSystem<'ctx>

§

impl<'ctx> RefUnwindSafe for FileSystem<'ctx>

§

impl<'ctx> Unpin for FileSystem<'ctx>

§

impl<'ctx> UnsafeUnpin for FileSystem<'ctx>

§

impl<'ctx> UnwindSafe for FileSystem<'ctx>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.