mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
return entire self taken
This commit is contained in:
parent
25bcb58fc4
commit
32c238da4d
2 changed files with 10 additions and 7 deletions
|
|
@ -52,7 +52,7 @@ impl Connection {
|
||||||
callback(
|
callback(
|
||||||
self,
|
self,
|
||||||
match input {
|
match input {
|
||||||
Ok(buffer) => Ok(buffer.to_utf8()),
|
Ok(this) => Ok(this.buffer().to_utf8()),
|
||||||
Err(error) => Err(match error {
|
Err(error) => Err(match error {
|
||||||
input::Error::BufferOverflow => Error::InputBufferOverflow,
|
input::Error::BufferOverflow => Error::InputBufferOverflow,
|
||||||
input::Error::BufferWrite => Error::InputBufferWrite,
|
input::Error::BufferWrite => Error::InputBufferWrite,
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ impl Input {
|
||||||
|
|
||||||
/// Synchronously read all bytes from `gio::InputStream` to `input::Buffer`
|
/// Synchronously read all bytes from `gio::InputStream` to `input::Buffer`
|
||||||
///
|
///
|
||||||
|
/// Return `Self` with `buffer` updated on success
|
||||||
|
///
|
||||||
/// Options:
|
/// Options:
|
||||||
/// * `cancellable` https://docs.gtk.org/gio/class.Cancellable.html
|
/// * `cancellable` https://docs.gtk.org/gio/class.Cancellable.html
|
||||||
/// * `chunk` max bytes to read per chunk (256 by default)
|
/// * `chunk` max bytes to read per chunk (256 by default)
|
||||||
|
|
@ -38,7 +40,7 @@ impl Input {
|
||||||
mut self,
|
mut self,
|
||||||
cancelable: Option<Cancellable>,
|
cancelable: Option<Cancellable>,
|
||||||
chunk: Option<usize>,
|
chunk: Option<usize>,
|
||||||
) -> Result<Buffer, Error> {
|
) -> Result<Self, Error> {
|
||||||
loop {
|
loop {
|
||||||
// Continue bytes reading
|
// Continue bytes reading
|
||||||
match self.stream.read_bytes(
|
match self.stream.read_bytes(
|
||||||
|
|
@ -55,7 +57,7 @@ impl Input {
|
||||||
Ok(bytes) => {
|
Ok(bytes) => {
|
||||||
// No bytes were read, end of stream
|
// No bytes were read, end of stream
|
||||||
if bytes.len() == 0 {
|
if bytes.len() == 0 {
|
||||||
return Ok(self.buffer);
|
return Ok(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save chunk to buffer
|
// Save chunk to buffer
|
||||||
|
|
@ -70,9 +72,10 @@ impl Input {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Asynchronously read all bytes from `gio::InputStream` to `input::Buffer`,
|
/// Asynchronously read all bytes from `gio::InputStream` to `input::Buffer`
|
||||||
///
|
///
|
||||||
/// applies `callback` function on last byte reading complete.
|
/// * applies `callback` function on last byte reading complete;
|
||||||
|
/// * return `Self` with `buffer` updated on success
|
||||||
///
|
///
|
||||||
/// Options:
|
/// Options:
|
||||||
/// * `cancellable` https://docs.gtk.org/gio/class.Cancellable.html (`None::<&Cancellable>` by default)
|
/// * `cancellable` https://docs.gtk.org/gio/class.Cancellable.html (`None::<&Cancellable>` by default)
|
||||||
|
|
@ -84,7 +87,7 @@ impl Input {
|
||||||
cancelable: Option<Cancellable>,
|
cancelable: Option<Cancellable>,
|
||||||
priority: Option<Priority>,
|
priority: Option<Priority>,
|
||||||
chunk: Option<usize>,
|
chunk: Option<usize>,
|
||||||
callback: impl FnOnce(Result<Buffer, Error>) + 'static,
|
callback: impl FnOnce(Result<Self, Error>) + 'static,
|
||||||
) {
|
) {
|
||||||
// Continue bytes reading
|
// Continue bytes reading
|
||||||
self.stream.clone().read_bytes_async(
|
self.stream.clone().read_bytes_async(
|
||||||
|
|
@ -106,7 +109,7 @@ impl Input {
|
||||||
Ok(bytes) => {
|
Ok(bytes) => {
|
||||||
// No bytes were read, end of stream
|
// No bytes were read, end of stream
|
||||||
if bytes.len() == 0 {
|
if bytes.len() == 0 {
|
||||||
return callback(Ok(self.buffer));
|
return callback(Ok(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save chunk to buffer
|
// Save chunk to buffer
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue