pub trait OutputStreamExt: 'static {
Show 18 methods // Required methods fn clear_pending(&self); fn close( &self, cancellable: Option<&impl IsA<Cancellable>> ) -> Result<(), Error>; 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 flush( &self, cancellable: Option<&impl IsA<Cancellable>> ) -> Result<(), Error>; fn flush_async<P: FnOnce(Result<(), Error>) + 'static>( &self, io_priority: Priority, cancellable: Option<&impl IsA<Cancellable>>, callback: P ); fn flush_future( &self, io_priority: Priority ) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>>; fn has_pending(&self) -> bool; fn is_closed(&self) -> bool; fn is_closing(&self) -> bool; fn set_pending(&self) -> Result<(), Error>; fn splice( &self, source: &impl IsA<InputStream>, flags: OutputStreamSpliceFlags, cancellable: Option<&impl IsA<Cancellable>> ) -> Result<isize, Error>; fn splice_async<P: FnOnce(Result<isize, Error>) + 'static>( &self, source: &impl IsA<InputStream>, flags: OutputStreamSpliceFlags, io_priority: Priority, cancellable: Option<&impl IsA<Cancellable>>, callback: P ); fn splice_future( &self, source: &impl IsA<InputStream> + Clone + 'static, flags: OutputStreamSpliceFlags, io_priority: Priority ) -> Pin<Box_<dyn Future<Output = Result<isize, Error>> + 'static>>; fn write( &self, buffer: &[u8], cancellable: Option<&impl IsA<Cancellable>> ) -> Result<isize, Error>; fn write_bytes( &self, bytes: &Bytes, cancellable: Option<&impl IsA<Cancellable>> ) -> Result<isize, Error>; fn write_bytes_async<P: FnOnce(Result<isize, Error>) + 'static>( &self, bytes: &Bytes, io_priority: Priority, cancellable: Option<&impl IsA<Cancellable>>, callback: P ); fn write_bytes_future( &self, bytes: &Bytes, io_priority: Priority ) -> Pin<Box_<dyn Future<Output = Result<isize, Error>> + 'static>>;
}
Expand description

Required Methods§

source

fn clear_pending(&self)

Clears the pending flag on self.

source

fn close( &self, cancellable: Option<&impl IsA<Cancellable>> ) -> Result<(), Error>

Closes the stream, releasing resources related to it.

Once the stream is closed, all other operations will return IOErrorEnum::Closed. Closing a stream multiple times will not return an error.

Closing a stream will automatically flush any outstanding buffers in the stream.

Streams will be automatically closed when the last reference is dropped, but you might want to call this function to make sure resources are released as early as possible.

Some streams might keep the backing store of the stream (e.g. a file descriptor) open after the stream is closed. See the documentation for the individual stream for details.

On failure the first error that happened will be reported, but the close operation will finish as much as possible. A stream that failed to close will still return IOErrorEnum::Closed for all operations. Still, it is important to check and report the error to the user, otherwise there might be a loss of data as all data might not be written.

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. Cancelling a close will still leave the stream closed, but there some streams can use a faster close that doesn’t block to e.g. check errors. On cancellation (as with any error) there is no guarantee that all written data will reach the target.

cancellable

optional cancellable object

Returns

true on success, false on failure

source

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

Requests an asynchronous close of the stream, releasing resources related to it. When the operation is finished callback will be called. You can then call g_output_stream_close_finish() to get the result of the operation.

For behaviour details see close().

The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

io_priority

the io priority of the request.

cancellable

optional cancellable object

callback

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 flush( &self, cancellable: Option<&impl IsA<Cancellable>> ) -> Result<(), Error>

Forces a write of all user-space buffered data for the given self. Will block during the operation. Closing the stream will implicitly cause a flush.

This function is optional for inherited classes.

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.

cancellable

optional cancellable object

Returns

true on success, false on error

source

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

Forces an asynchronous write of all user-space buffered data for the given self. For behaviour details see flush().

When the operation is finished callback will be called. You can then call g_output_stream_flush_finish() to get the result of the operation.

io_priority

the io priority of the request.

cancellable

optional Cancellable object, None to ignore.

callback

a GAsyncReadyCallback to call when the request is satisfied

source

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

source

fn has_pending(&self) -> bool

Checks if an output stream has pending actions.

Returns

true if self has pending actions.

source

fn is_closed(&self) -> bool

Checks if an output stream has already been closed.

Returns

true if self is closed. false otherwise.

source

fn is_closing(&self) -> bool

Checks if an output stream is being closed. This can be used inside e.g. a flush implementation to see if the flush (or other i/o operation) is called from within the closing operation.

Returns

true if self is being closed. false otherwise.

source

fn set_pending(&self) -> Result<(), Error>

Sets self to have actions pending. If the pending flag is already set or self is closed, it will return false and set error.

Returns

true if pending was previously unset and is now set.

source

fn splice( &self, source: &impl IsA<InputStream>, flags: OutputStreamSpliceFlags, cancellable: Option<&impl IsA<Cancellable>> ) -> Result<isize, Error>

Splices an input stream into an output stream.

source

a InputStream.

flags

a set of OutputStreamSpliceFlags.

cancellable

optional Cancellable object, None to ignore.

Returns

a gssize containing the size of the data spliced, or -1 if an error occurred. Note that if the number of bytes spliced is greater than G_MAXSSIZE, then that will be returned, and there is no way to determine the actual number of bytes spliced.

source

fn splice_async<P: FnOnce(Result<isize, Error>) + 'static>( &self, source: &impl IsA<InputStream>, flags: OutputStreamSpliceFlags, io_priority: Priority, cancellable: Option<&impl IsA<Cancellable>>, callback: P )

Splices a stream asynchronously. When the operation is finished callback will be called. You can then call g_output_stream_splice_finish() to get the result of the operation.

For the synchronous, blocking version of this function, see splice().

source

a InputStream.

flags

a set of OutputStreamSpliceFlags.

io_priority

the io priority of the request.

cancellable

optional Cancellable object, None to ignore.

callback

a GAsyncReadyCallback.

source

fn splice_future( &self, source: &impl IsA<InputStream> + Clone + 'static, flags: OutputStreamSpliceFlags, io_priority: Priority ) -> Pin<Box_<dyn Future<Output = Result<isize, Error>> + 'static>>

source

fn write( &self, buffer: &[u8], cancellable: Option<&impl IsA<Cancellable>> ) -> Result<isize, Error>

Tries to write count bytes from buffer into the stream. Will block during the operation.

If count is 0, returns 0 and does nothing. A value of count larger than G_MAXSSIZE will cause a IOErrorEnum::InvalidArgument error.

On success, the number of bytes written to the stream is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial I/O error, or if there is not enough storage in the stream. All writes block until at least one byte is written or an error occurs; 0 is never returned (unless count is 0).

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. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

On error -1 is returned and error is set accordingly.

buffer

the buffer containing the data to write.

cancellable

optional cancellable object

Returns

Number of bytes written, or -1 on error

source

fn write_bytes( &self, bytes: &Bytes, cancellable: Option<&impl IsA<Cancellable>> ) -> Result<isize, Error>

A wrapper function for write() which takes a glib::Bytes as input. This can be more convenient for use by language bindings or in other cases where the refcounted nature of glib::Bytes is helpful over a bare pointer interface.

However, note that this function may still perform partial writes, just like write(). If that occurs, to continue writing, you will need to create a new glib::Bytes containing just the remaining bytes, using [glib::Bytes::new_from_bytes()][crate::glib::Bytes::new_from_bytes()]. Passing the same glib::Bytes instance multiple times potentially can result in duplicated data in the output stream.

bytes

the glib::Bytes to write

cancellable

optional cancellable object

Returns

Number of bytes written, or -1 on error

source

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

This function is similar to OutputStreamExtManual::write_async(), but takes a glib::Bytes as input. Due to the refcounted nature of glib::Bytes, this allows the stream to avoid taking a copy of the data.

However, note that this function may still perform partial writes, just like OutputStreamExtManual::write_async(). If that occurs, to continue writing, you will need to create a new glib::Bytes containing just the remaining bytes, using [glib::Bytes::new_from_bytes()][crate::glib::Bytes::new_from_bytes()]. Passing the same glib::Bytes instance multiple times potentially can result in duplicated data in the output stream.

For the synchronous, blocking version of this function, see write_bytes().

bytes

The bytes to write

io_priority

the io priority of the request.

cancellable

optional Cancellable object, None to ignore.

callback

callback to call when the request is satisfied

source

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

Implementors§