Skip to main content

FileEnumeratorExt

Trait FileEnumeratorExt 

Source
pub trait FileEnumeratorExt: IsA<FileEnumerator> + 'static {
    // Provided methods
    fn close_async<P: FnOnce(Result<(), Error>) + 'static>(
        &self,
        io_priority: Priority,
        cancellable: Option<&impl IsA<Cancellable>>,
        callback: P,
    ) { ... }
    fn close_future(
        &self,
        io_priority: Priority,
    ) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>> { ... }
    fn child(&self, info: &FileInfo) -> File { ... }
    fn container(&self) -> File { ... }
    fn has_pending(&self) -> bool { ... }
    fn is_closed(&self) -> bool { ... }
    fn next_file(
        &self,
        cancellable: Option<&impl IsA<Cancellable>>,
    ) -> Result<Option<FileInfo>, Error> { ... }
    fn next_files_async<P: FnOnce(Result<Vec<FileInfo>, Error>) + 'static>(
        &self,
        num_files: i32,
        io_priority: Priority,
        cancellable: Option<&impl IsA<Cancellable>>,
        callback: P,
    ) { ... }
    fn next_files_future(
        &self,
        num_files: i32,
        io_priority: Priority,
    ) -> Pin<Box_<dyn Future<Output = Result<Vec<FileInfo>, Error>> + 'static>> { ... }
    fn set_pending(&self, pending: bool) { ... }
}
Expand description

Trait containing all FileEnumerator methods.

§Implementors

FileEnumerator

Provided Methods§

Source

fn close_async<P: FnOnce(Result<(), Error>) + 'static>( &self, io_priority: Priority, cancellable: Option<&impl IsA<Cancellable>>, callback: P, )

Asynchronously closes the file enumerator.

If @cancellable is not NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error [error@Gio.IOErrorEnum.CANCELLED] will be returned by Gio::FileEnumerator::close_finish()()].

§io_priority

the I/O priority of the request

§cancellable

optional cancellable object

§callback

a callback to call when the request is satisfied

Source

fn close_future( &self, io_priority: Priority, ) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>>

Source

fn child(&self, info: &FileInfo) -> File

Returns a new File which refers to the file named by @info in the source directory of @self.

This function is primarily intended to be used inside loops with next_file().

To use this, Gio::FILE_ATTRIBUTE_STANDARD_NAME must have been listed in the attributes list used when creating the FileEnumerator.

This is a convenience method that’s equivalent to: ⚠️ The following code is in c ⚠️

char *name = g_file_info_get_name (info);
GFile *child = g_file_get_child (g_file_enumerator_get_container (enumerator), name);
§info

a file info object received from next_file() or the async equivalent

§Returns

a file object for the file info object passed to it

Source

fn container(&self) -> File

Get the File container which is being enumerated.

§Returns

the file which is being enumerated

Source

fn has_pending(&self) -> bool

Checks if the file enumerator has pending operations.

§Returns

true if the @self has pending operations

Source

fn is_closed(&self) -> bool

Checks if the file enumerator has been closed.

§Returns

true if the @self is closed

Source

fn next_file( &self, cancellable: Option<&impl IsA<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

Source

fn next_files_async<P: FnOnce(Result<Vec<FileInfo>, Error>) + 'static>( &self, num_files: i32, io_priority: Priority, cancellable: Option<&impl IsA<Cancellable>>, callback: P, )

Request information for a number of files from the enumerator asynchronously.

When all I/O for the operation is finished the @callback will be called with the requested information.

See the documentation of FileEnumerator for information about the order of returned files.

Once the end of the enumerator is reached, or if an error occurs, the @callback will be called with an empty list. In this case, the previous call to next_files_async() will typically have returned fewer than @num_files items.

If a request is cancelled the callback will be called with [error@Gio.IOErrorEnum.CANCELLED].

This leads to the following pseudo-code usage: ⚠️ The following code is in c ⚠️

g_autoptr(GFile) dir = get_directory ();
g_autoptr(GFileEnumerator) enumerator = NULL;
g_autolist(GFileInfo) files = NULL;
g_autoptr(GError) local_error = NULL;

enumerator = yield g_file_enumerate_children_async (dir,
                                                    G_FILE_ATTRIBUTE_STANDARD_NAME ","
                                                    G_FILE_ATTRIBUTE_STANDARD_TYPE,
                                                    G_FILE_QUERY_INFO_NONE,
                                                    G_PRIORITY_DEFAULT,
                                                    cancellable,
                                                    …,
                                                    &local_error);
if (enumerator == NULL)
  g_error ("Error enumerating: %s", local_error->message);

// Loop until no files are returned, either because the end of the enumerator
// has been reached, or an error was returned.
do
  {
    files = yield g_file_enumerator_next_files_async (enumerator,
                                                      5,  // number of files to request
                                                      G_PRIORITY_DEFAULT,
                                                      cancellable,
                                                      …,
                                                      &local_error);

    // Process the returned files, but don’t assume that exactly 5 were returned.
    for (GList *l = files; l != NULL; l = l->next)
      {
        GFileInfo *info = l->data;
        handle_file_info (info);
      }
  }
while (files != NULL);

if (local_error != NULL &&
    !g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
  g_error ("Error while enumerating: %s", local_error->message);

During an async request no other sync and async calls are allowed, and will result in [error@Gio.IOErrorEnum.PENDING] errors.

Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is GLib::PRIORITY_DEFAULT.

§num_files

the number of file info objects to request

§io_priority

the I/O priority of the request

§cancellable

optional cancellable object

§callback

callback to call when the request is satisfied

Source

fn next_files_future( &self, num_files: i32, io_priority: Priority, ) -> Pin<Box_<dyn Future<Output = Result<Vec<FileInfo>, Error>> + 'static>>

Source

fn set_pending(&self, pending: bool)

Sets the file enumerator as having pending operations.

§pending

a boolean value

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§