Trait gio::prelude::OutputStreamExt [−][src]
pub trait OutputStreamExt: 'static {}Show methods
fn clear_pending(&self); fn close<P: IsA<Cancellable>>(
&self,
cancellable: Option<&P>
) -> Result<(), Error>; fn close_async<P: IsA<Cancellable>, Q: FnOnce(Result<(), Error>) + Send + 'static>(
&self,
io_priority: Priority,
cancellable: Option<&P>,
callback: Q
); fn close_async_future(
&self,
io_priority: Priority
) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>>; fn flush<P: IsA<Cancellable>>(
&self,
cancellable: Option<&P>
) -> Result<(), Error>; fn flush_async<P: IsA<Cancellable>, Q: FnOnce(Result<(), Error>) + Send + 'static>(
&self,
io_priority: Priority,
cancellable: Option<&P>,
callback: Q
); fn flush_async_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<P: IsA<InputStream>, Q: IsA<Cancellable>>(
&self,
source: &P,
flags: OutputStreamSpliceFlags,
cancellable: Option<&Q>
) -> Result<isize, Error>; fn splice_async<P: IsA<InputStream>, Q: IsA<Cancellable>, R: FnOnce(Result<isize, Error>) + Send + 'static>(
&self,
source: &P,
flags: OutputStreamSpliceFlags,
io_priority: Priority,
cancellable: Option<&Q>,
callback: R
); fn splice_async_future<P: IsA<InputStream> + Clone + 'static>(
&self,
source: &P,
flags: OutputStreamSpliceFlags,
io_priority: Priority
) -> Pin<Box_<dyn Future<Output = Result<isize, Error>> + 'static>>; fn write<P: IsA<Cancellable>>(
&self,
buffer: &[u8],
cancellable: Option<&P>
) -> Result<isize, Error>; fn write_bytes<P: IsA<Cancellable>>(
&self,
bytes: &Bytes,
cancellable: Option<&P>
) -> Result<isize, Error>; fn write_bytes_async<P: IsA<Cancellable>, Q: FnOnce(Result<isize, Error>) + Send + 'static>(
&self,
bytes: &Bytes,
io_priority: Priority,
cancellable: Option<&P>,
callback: Q
); fn write_bytes_async_future(
&self,
bytes: &Bytes,
io_priority: Priority
) -> Pin<Box_<dyn Future<Output = Result<isize, Error>> + 'static>>;
Expand description
Trait containing all OutputStream
methods.
Implementors
FileOutputStream
, FilterOutputStream
, MemoryOutputStream
, OutputStream
, PollableOutputStream
, UnixOutputStream
Required methods
fn clear_pending(&self)
fn clear_pending(&self)
Clears the pending flag on self
.
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
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
fn close_async_future(
&self,
io_priority: Priority
) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>>
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
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
fn flush_async_future(
&self,
io_priority: Priority
) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>>
fn has_pending(&self) -> bool
fn has_pending(&self) -> bool
fn is_closing(&self) -> bool
fn is_closing(&self) -> bool
fn set_pending(&self) -> Result<(), Error>
fn set_pending(&self) -> Result<(), Error>
fn splice<P: IsA<InputStream>, Q: IsA<Cancellable>>(
&self,
source: &P,
flags: OutputStreamSpliceFlags,
cancellable: Option<&Q>
) -> Result<isize, Error>
fn splice<P: IsA<InputStream>, Q: IsA<Cancellable>>(
&self,
source: &P,
flags: OutputStreamSpliceFlags,
cancellable: Option<&Q>
) -> 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.
fn splice_async<P: IsA<InputStream>, Q: IsA<Cancellable>, R: FnOnce(Result<isize, Error>) + Send + 'static>(
&self,
source: &P,
flags: OutputStreamSpliceFlags,
io_priority: Priority,
cancellable: Option<&Q>,
callback: R
)
fn splice_async<P: IsA<InputStream>, Q: IsA<Cancellable>, R: FnOnce(Result<isize, Error>) + Send + 'static>(
&self,
source: &P,
flags: OutputStreamSpliceFlags,
io_priority: Priority,
cancellable: Option<&Q>,
callback: R
)
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
.
fn splice_async_future<P: IsA<InputStream> + Clone + 'static>(
&self,
source: &P,
flags: OutputStreamSpliceFlags,
io_priority: Priority
) -> Pin<Box_<dyn Future<Output = Result<isize, Error>> + 'static>>
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
fn write_bytes<P: IsA<Cancellable>>(
&self,
bytes: &Bytes,
cancellable: Option<&P>
) -> Result<isize, Error>
fn write_bytes<P: IsA<Cancellable>>(
&self,
bytes: &Bytes,
cancellable: Option<&P>
) -> 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
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