Trait FileEnumeratorImpl

Source
pub trait FileEnumeratorImpl: ObjectImpl + ObjectSubclass<Type: IsA<FileEnumerator>> {
    // Provided methods
    fn next_file(
        &self,
        cancellable: Option<&Cancellable>,
    ) -> Result<Option<FileInfo>, Error> { ... }
    fn close(&self, cancellable: Option<&Cancellable>) -> (bool, Option<Error>) { ... }
}

Provided Methods§

Source

fn next_file( &self, cancellable: Option<&Cancellable>, ) -> Result<Option<FileInfo>, Error>

Source

fn close(&self, cancellable: Option<&Cancellable>) -> (bool, Option<Error>)

Closes the enumerator (see FileEnumeratorExt::close).

NOTE: If the enumerator has not been explicitly closed, GIO closes it when the object is dropped. But GIO does it by calling close vfunc in finalize, which is not safe and could lead to undefined behavior, such as accessing freed memory or resources, which can cause crashes or other unexpected behavior.

An issue has been opened in GLib to address this: https://gitlab.gnome.org/GNOME/glib/-/issues/3713 and a MR has been opened to fix it: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4672.

Until this is fixed, it is unsafe to rely on the enumerator being closed when the object is dropped. It is recommended to close the enumerator explicitly before dropping it, by calling FileEnumeratorExt::close, or to implement the ObjectImpl::dispose method and call FileEnumeratorExt::close there (it is safe to access the object there):

pub struct MyFileEnumerator();

#[glib::object_subclass]
impl ObjectSubclass for MyFileEnumerator { ... }

impl ObjectImpl for MyFileEnumerator {
    fn dispose(&self) {
        // close the enumerator here is safe and avoids `finalize` to call close.
        let _ = self.obj().close(Cancellable::NONE);
    }
}

impl FileEnumeratorImpl for MyFileEnumerator { ... }

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§