pub trait FileEnumeratorImpl: ObjectImpl + ObjectSubclass<Type: IsA<FileEnumerator>> {
// Provided methods
fn next_file(
&self,
cancellable: Option<&Cancellable>,
) -> Result<Option<FileInfo>, Error> { ... }
fn next_files_future(
&self,
num_files: i32,
priority: Priority,
) -> Pin<Box<dyn Future<Output = Result<List<FileInfo>, Error>> + 'static>> { ... }
fn close(&self, cancellable: Option<&Cancellable>) -> (bool, Option<Error>) { ... }
fn close_future(
&self,
io_priority: Priority,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static>> { ... }
}Provided Methods§
Sourcefn next_file(
&self,
cancellable: Option<&Cancellable>,
) -> Result<Option<FileInfo>, Error>
fn next_file( &self, cancellable: Option<&Cancellable>, ) -> Result<Option<FileInfo>, Error>
Returns information for the next file in the enumerated object.
Will block until the information is available. The FileInfo
returned from this function will contain attributes that match the
attribute string that was passed when the file enumerator was created.
See the documentation of FileEnumerator for information about the
order of returned files.
On error, returns NULL and sets @error to the error. If the
enumerator is at the end, NULL will be returned and @error will
be unset.
§cancellable
optional cancellable object
§Returns
A file info object, or NULL on error
or end of enumerator
fn next_files_future( &self, num_files: i32, priority: Priority, ) -> Pin<Box<dyn Future<Output = Result<List<FileInfo>, Error>> + 'static>>
Sourcefn close(&self, cancellable: Option<&Cancellable>) -> (bool, Option<Error>)
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 { ... }fn close_future( &self, io_priority: Priority, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static>>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".