// GENERATED — DO NOT EDIT

///|
/// [Upstream documentation](https://docs.gtk.org/gio/class.OutputStream.html).
pub type OutputStream

///|
pub(open) trait IOutputStream {
  fn as_output_stream(Self) -> OutputStream
  fn clear_pending(Self) -> Unit = _
  fn close(Self, &ICancellable?) -> Bool raise @glib.Error_ = _
  fn flush(Self, &ICancellable?) -> Bool raise @glib.Error_ = _
  fn has_pending(Self) -> Bool = _
  fn is_closed(Self) -> Bool = _
  fn is_closing(Self) -> Bool = _
  fn set_pending(Self) -> Bool raise @glib.Error_ = _
  fn splice(Self, &IInputStream, OutputStreamSpliceFlags, &ICancellable?) -> Int64 raise @glib.Error_ = _
  fn write_all_finish(Self, &IAsyncResult) -> (Bool, UInt64) raise @glib.Error_ = _
  fn write_bytes(Self, Bytes, &ICancellable?) -> Int64 raise @glib.Error_ = _
  fn write_finish(Self, &IAsyncResult) -> Int64 raise @glib.Error_ = _
  fn writev_all_finish(Self, &IAsyncResult) -> (Bool, UInt64) raise @glib.Error_ = _
  fn writev_finish(Self, &IAsyncResult) -> (Bool, UInt64) raise @glib.Error_ = _
  fn close_async(
    Self,
    Int,
    &ICancellable?,
    (Result[Bool, @glib.Error_]) -> Unit,
  ) -> Unit = _
  fn flush_async(
    Self,
    Int,
    &ICancellable?,
    (Result[Bool, @glib.Error_]) -> Unit,
  ) -> Unit = _
  fn splice_async(
    Self,
    &IInputStream,
    OutputStreamSpliceFlags,
    Int,
    &ICancellable?,
    (Result[Int64, @glib.Error_]) -> Unit,
  ) -> Unit = _
  fn write_bytes_async(
    Self,
    Bytes,
    Int,
    &ICancellable?,
    (Result[Int64, @glib.Error_]) -> Unit,
  ) -> Unit = _
}

///|
pub impl IOutputStream for OutputStream with fn as_output_stream(self) {
  self
}

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.clear_pending.html).
#borrow(self)
pub extern "c" fn OutputStream::clear_pending(self : OutputStream) = "moonbit_g_output_stream_clear_pending"

///|
#borrow(self_, cancellable, error)
extern "c" fn moonbit_g_output_stream_close(
  self_ : OutputStream,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Bool = "moonbit_g_output_stream_close"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.close.html).
pub fn OutputStream::close(
  self : OutputStream,
  cancellable : &ICancellable?,
) -> Bool raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_output_stream_close(
    self,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, cancellable, error)
extern "c" fn moonbit_g_output_stream_flush(
  self_ : OutputStream,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Bool = "moonbit_g_output_stream_flush"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.flush.html).
pub fn OutputStream::flush(
  self : OutputStream,
  cancellable : &ICancellable?,
) -> Bool raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_output_stream_flush(
    self,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.has_pending.html).
#borrow(self)
pub extern "c" fn OutputStream::has_pending(self : OutputStream) -> Bool = "moonbit_g_output_stream_has_pending"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.is_closed.html).
#borrow(self)
pub extern "c" fn OutputStream::is_closed(self : OutputStream) -> Bool = "moonbit_g_output_stream_is_closed"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.is_closing.html).
#borrow(self)
pub extern "c" fn OutputStream::is_closing(self : OutputStream) -> Bool = "moonbit_g_output_stream_is_closing"

///|
#borrow(self_, error)
extern "c" fn moonbit_g_output_stream_set_pending(
  self_ : OutputStream,
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Bool = "moonbit_g_output_stream_set_pending"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.set_pending.html).
pub fn OutputStream::set_pending(
  self : OutputStream,
) -> Bool raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_output_stream_set_pending(self, error_)
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, source, cancellable, error)
extern "c" fn moonbit_g_output_stream_splice(
  self_ : OutputStream,
  source : InputStream,
  flags : Int,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Int64 = "moonbit_g_output_stream_splice"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.splice.html).
pub fn OutputStream::splice(
  self : OutputStream,
  source : &IInputStream,
  flags : OutputStreamSpliceFlags,
  cancellable : &ICancellable?,
) -> Int64 raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_output_stream_splice(
    self,
    source.as_input_stream(),
    flags.to_int(),
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, result, bytes_written, error)
extern "c" fn moonbit_g_output_stream_write_all_finish(
  self_ : OutputStream,
  result : AsyncResult,
  bytes_written : Ref[UInt64],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Bool = "moonbit_g_output_stream_write_all_finish"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.write_all_finish.html).
pub fn OutputStream::write_all_finish(
  self : OutputStream,
  result : &IAsyncResult,
) -> (Bool, UInt64) raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let bytes_written = Ref(0UL)
  let result = moonbit_g_output_stream_write_all_finish(
    self,
    result.as_async_result(),
    bytes_written,
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  (result, bytes_written.val)
}

///|
#borrow(self_, bytes, cancellable, error)
extern "c" fn moonbit_g_output_stream_write_bytes(
  self_ : OutputStream,
  bytes : Bytes,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Int64 = "moonbit_g_output_stream_write_bytes"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.write_bytes.html).
pub fn OutputStream::write_bytes(
  self : OutputStream,
  bytes : Bytes,
  cancellable : &ICancellable?,
) -> Int64 raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_output_stream_write_bytes(
    self,
    bytes,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, result, error)
extern "c" fn moonbit_g_output_stream_write_finish(
  self_ : OutputStream,
  result : AsyncResult,
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Int64 = "moonbit_g_output_stream_write_finish"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.write_finish.html).
pub fn OutputStream::write_finish(
  self : OutputStream,
  result : &IAsyncResult,
) -> Int64 raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_output_stream_write_finish(
    self,
    result.as_async_result(),
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, result, bytes_written, error)
extern "c" fn moonbit_g_output_stream_writev_all_finish(
  self_ : OutputStream,
  result : AsyncResult,
  bytes_written : Ref[UInt64],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Bool = "moonbit_g_output_stream_writev_all_finish"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.writev_all_finish.html).
pub fn OutputStream::writev_all_finish(
  self : OutputStream,
  result : &IAsyncResult,
) -> (Bool, UInt64) raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let bytes_written = Ref(0UL)
  let result = moonbit_g_output_stream_writev_all_finish(
    self,
    result.as_async_result(),
    bytes_written,
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  (result, bytes_written.val)
}

///|
#borrow(self_, result, bytes_written, error)
extern "c" fn moonbit_g_output_stream_writev_finish(
  self_ : OutputStream,
  result : AsyncResult,
  bytes_written : Ref[UInt64],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Bool = "moonbit_g_output_stream_writev_finish"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.writev_finish.html).
pub fn OutputStream::writev_finish(
  self : OutputStream,
  result : &IAsyncResult,
) -> (Bool, UInt64) raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let bytes_written = Ref(0UL)
  let result = moonbit_g_output_stream_writev_finish(
    self,
    result.as_async_result(),
    bytes_written,
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  (result, bytes_written.val)
}

///|
#borrow(self_, cancellable)
extern "c" fn g_output_stream_close_async(
  self_ : OutputStream,
  io_priority : Int,
  cancellable : @glib.Nullable[Cancellable],
  function : FuncRef[
    (
      Bool,
      @glib.Nullable[@glib.Error_],
      (Bool, @glib.Nullable[@glib.Error_]) -> Unit,
    ) -> Unit,
  ],
  closure : (Bool, @glib.Nullable[@glib.Error_]) -> Unit,
) = "moonbit_g_output_stream_close_async"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.close_async.html).
pub fn OutputStream::close_async(
  self : OutputStream,
  io_priority : Int,
  cancellable : &ICancellable?,
  callback : (Result[Bool, @glib.Error_]) -> Unit,
) -> Unit {
  g_output_stream_close_async(
    self,
    io_priority,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    fn(result, error, f) { f(result, error) },
    fn(result, error) {
      match error.to_option() {
        Some(e) => callback(Err(e))
        None => callback(Ok(result))
      }
    },
  )
}

///|
#borrow(self_, cancellable)
extern "c" fn g_output_stream_flush_async(
  self_ : OutputStream,
  io_priority : Int,
  cancellable : @glib.Nullable[Cancellable],
  function : FuncRef[
    (
      Bool,
      @glib.Nullable[@glib.Error_],
      (Bool, @glib.Nullable[@glib.Error_]) -> Unit,
    ) -> Unit,
  ],
  closure : (Bool, @glib.Nullable[@glib.Error_]) -> Unit,
) = "moonbit_g_output_stream_flush_async"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.flush_async.html).
pub fn OutputStream::flush_async(
  self : OutputStream,
  io_priority : Int,
  cancellable : &ICancellable?,
  callback : (Result[Bool, @glib.Error_]) -> Unit,
) -> Unit {
  g_output_stream_flush_async(
    self,
    io_priority,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    fn(result, error, f) { f(result, error) },
    fn(result, error) {
      match error.to_option() {
        Some(e) => callback(Err(e))
        None => callback(Ok(result))
      }
    },
  )
}

///|
#borrow(self_, source, cancellable)
extern "c" fn g_output_stream_splice_async(
  self_ : OutputStream,
  source : InputStream,
  flags : Int,
  io_priority : Int,
  cancellable : @glib.Nullable[Cancellable],
  function : FuncRef[
    (
      Int64,
      @glib.Nullable[@glib.Error_],
      (Int64, @glib.Nullable[@glib.Error_]) -> Unit,
    ) -> Unit,
  ],
  closure : (Int64, @glib.Nullable[@glib.Error_]) -> Unit,
) = "moonbit_g_output_stream_splice_async"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.splice_async.html).
pub fn OutputStream::splice_async(
  self : OutputStream,
  source : &IInputStream,
  flags : OutputStreamSpliceFlags,
  io_priority : Int,
  cancellable : &ICancellable?,
  callback : (Result[Int64, @glib.Error_]) -> Unit,
) -> Unit {
  g_output_stream_splice_async(
    self,
    source.as_input_stream(),
    flags.to_int(),
    io_priority,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    fn(result, error, f) { f(result, error) },
    fn(result, error) {
      match error.to_option() {
        Some(e) => callback(Err(e))
        None => callback(Ok(result))
      }
    },
  )
}

///|
#borrow(self_, bytes, cancellable)
extern "c" fn g_output_stream_write_bytes_async(
  self_ : OutputStream,
  bytes : Bytes,
  io_priority : Int,
  cancellable : @glib.Nullable[Cancellable],
  function : FuncRef[
    (
      Int64,
      @glib.Nullable[@glib.Error_],
      (Int64, @glib.Nullable[@glib.Error_]) -> Unit,
    ) -> Unit,
  ],
  closure : (Int64, @glib.Nullable[@glib.Error_]) -> Unit,
) = "moonbit_g_output_stream_write_bytes_async"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.OutputStream.write_bytes_async.html).
pub fn OutputStream::write_bytes_async(
  self : OutputStream,
  bytes : Bytes,
  io_priority : Int,
  cancellable : &ICancellable?,
  callback : (Result[Int64, @glib.Error_]) -> Unit,
) -> Unit {
  g_output_stream_write_bytes_async(
    self,
    bytes,
    io_priority,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    fn(result, error, f) { f(result, error) },
    fn(result, error) {
      match error.to_option() {
        Some(e) => callback(Err(e))
        None => callback(Ok(result))
      }
    },
  )
}

///|
impl IOutputStream with fn clear_pending(self) -> Unit {
  self.as_output_stream().clear_pending()
}

///|
impl IOutputStream with fn close(self, cancellable) -> Bool raise @glib.Error_ {
  self.as_output_stream().close(cancellable)
}

///|
impl IOutputStream with fn flush(self, cancellable) -> Bool raise @glib.Error_ {
  self.as_output_stream().flush(cancellable)
}

///|
impl IOutputStream with fn has_pending(self) -> Bool {
  self.as_output_stream().has_pending()
}

///|
impl IOutputStream with fn is_closed(self) -> Bool {
  self.as_output_stream().is_closed()
}

///|
impl IOutputStream with fn is_closing(self) -> Bool {
  self.as_output_stream().is_closing()
}

///|
impl IOutputStream with fn set_pending(self) -> Bool raise @glib.Error_ {
  self.as_output_stream().set_pending()
}

///|
impl IOutputStream with fn splice(self, source, flags, cancellable) -> Int64 raise @glib.Error_ {
  self.as_output_stream().splice(source, flags, cancellable)
}

///|
impl IOutputStream with fn write_all_finish(self, result) -> (Bool, UInt64) raise @glib.Error_ {
  self.as_output_stream().write_all_finish(result)
}

///|
impl IOutputStream with fn write_bytes(self, bytes, cancellable) -> Int64 raise @glib.Error_ {
  self.as_output_stream().write_bytes(bytes, cancellable)
}

///|
impl IOutputStream with fn write_finish(self, result) -> Int64 raise @glib.Error_ {
  self.as_output_stream().write_finish(result)
}

///|
impl IOutputStream with fn writev_all_finish(self, result) -> (Bool, UInt64) raise @glib.Error_ {
  self.as_output_stream().writev_all_finish(result)
}

///|
impl IOutputStream with fn writev_finish(self, result) -> (Bool, UInt64) raise @glib.Error_ {
  self.as_output_stream().writev_finish(result)
}

///|
impl IOutputStream with fn close_async(self, io_priority, cancellable, callback) -> Unit {
  self.as_output_stream().close_async(io_priority, cancellable, callback)
}

///|
impl IOutputStream with fn flush_async(self, io_priority, cancellable, callback) -> Unit {
  self.as_output_stream().flush_async(io_priority, cancellable, callback)
}

///|
impl IOutputStream with fn splice_async(
  self,
  source,
  flags,
  io_priority,
  cancellable,
  callback,
) -> Unit {
  self
  .as_output_stream()
  .splice_async(source, flags, io_priority, cancellable, callback)
}

///|
impl IOutputStream with fn write_bytes_async(
  self,
  bytes,
  io_priority,
  cancellable,
  callback,
) -> Unit {
  self
  .as_output_stream()
  .write_bytes_async(bytes, io_priority, cancellable, callback)
}

///|
pub fn OutputStream::as_gobject_object(self : OutputStream) -> @gobject.Object = "%identity"

///|
pub impl @gobject.IObject for OutputStream with fn as_object(self) {
  self.as_gobject_object()
}