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 None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error IOErrorEnum::Cancelled will be returned in g_file_enumerator_close_finish().

§io_priority

the I/O priority of the request

§cancellable

optional #GCancellable object, None to ignore.

§callback

a #GAsyncReadyCallback 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

Return a new #GFile 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 g_file_enumerator_next_file().

To use this, FILE_ATTRIBUTE_STANDARD_NAME must have been listed in the attributes list used when creating the #GFileEnumerator.

This is a convenience method that’s equivalent to:

⚠️ The following code is in C ⚠️

  gchar *name = g_file_info_get_name (info);
  GFile *child = g_file_get_child (g_file_enumerator_get_container (enumr),
                                   name);
§info

a #GFileInfo gotten from g_file_enumerator_next_file() or the async equivalents.

§Returns

a #GFile for the #GFileInfo passed it.

Source

fn container(&self) -> File

Get the #GFile container which is being enumerated.

§Returns

the #GFile 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 #GFileInfo returned from this function will contain attributes that match the attribute string that was passed when the #GFileEnumerator was created.

See the documentation of #GFileEnumerator for information about the order of returned files.

On error, returns None and sets @error to the error. If the enumerator is at the end, None will be returned and @error will be unset.

§cancellable

optional #GCancellable object, None to ignore.

§Returns

A #GFileInfo or None on error or end of enumerator. Free the returned object with g_object_unref() when no longer needed.

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 #GFileEnumerator 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 g_file_enumerator_next_files_async() will typically have returned fewer than @num_files items.

If a request is cancelled the callback will be called with IOErrorEnum::Cancelled.

This leads to the following pseudo-code usage:

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 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 G_PRIORITY_DEFAULT.

§num_files

the number of file info objects to request

§io_priority

the I/O priority of the request

§cancellable

optional #GCancellable object, None to ignore.

§callback

a #GAsyncReadyCallback 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", so this trait is not object safe.

Implementors§