// GENERATED — DO NOT EDIT

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

///|
pub(open) trait IUnixConnection {
  fn as_unix_connection(Self) -> UnixConnection
  fn receive_credentials(Self, &ICancellable?) -> Credentials raise @glib.Error_ = _
  fn receive_fd(Self, &ICancellable?) -> Int raise @glib.Error_ = _
  fn send_credentials(Self, &ICancellable?) -> Bool raise @glib.Error_ = _
  fn send_fd(Self, Int, &ICancellable?) -> Bool raise @glib.Error_ = _
  fn receive_credentials_async(
    Self,
    &ICancellable?,
    (Result[Credentials, @glib.Error_]) -> Unit,
  ) -> Unit = _
  fn send_credentials_async(
    Self,
    &ICancellable?,
    (Result[Bool, @glib.Error_]) -> Unit,
  ) -> Unit = _
}

///|
pub impl IUnixConnection for UnixConnection with fn as_unix_connection(self) {
  self
}

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

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.UnixConnection.receive_credentials.html).
pub fn UnixConnection::receive_credentials(
  self : UnixConnection,
  cancellable : &ICancellable?,
) -> Credentials raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_unix_connection_receive_credentials(
    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_unix_connection_receive_fd(
  self_ : UnixConnection,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Int = "moonbit_g_unix_connection_receive_fd"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.UnixConnection.receive_fd.html).
pub fn UnixConnection::receive_fd(
  self : UnixConnection,
  cancellable : &ICancellable?,
) -> Int raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_unix_connection_receive_fd(
    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_unix_connection_send_credentials(
  self_ : UnixConnection,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Bool = "moonbit_g_unix_connection_send_credentials"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.UnixConnection.send_credentials.html).
pub fn UnixConnection::send_credentials(
  self : UnixConnection,
  cancellable : &ICancellable?,
) -> Bool raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_unix_connection_send_credentials(
    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_unix_connection_send_fd(
  self_ : UnixConnection,
  fd : Int,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Bool = "moonbit_g_unix_connection_send_fd"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.UnixConnection.send_fd.html).
pub fn UnixConnection::send_fd(
  self : UnixConnection,
  fd : Int,
  cancellable : &ICancellable?,
) -> Bool raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_unix_connection_send_fd(
    self,
    fd,
    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)
extern "c" fn g_unix_connection_receive_credentials_async(
  self_ : UnixConnection,
  cancellable : @glib.Nullable[Cancellable],
  function : FuncRef[
    (
      @glib.Nullable[Credentials],
      @glib.Nullable[@glib.Error_],
      (@glib.Nullable[Credentials], @glib.Nullable[@glib.Error_]) -> Unit,
    ) -> Unit,
  ],
  closure : (@glib.Nullable[Credentials], @glib.Nullable[@glib.Error_]) -> Unit,
) = "moonbit_g_unix_connection_receive_credentials_async"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.UnixConnection.receive_credentials_async.html).
pub fn UnixConnection::receive_credentials_async(
  self : UnixConnection,
  cancellable : &ICancellable?,
  callback : (Result[Credentials, @glib.Error_]) -> Unit,
) -> Unit {
  g_unix_connection_receive_credentials_async(
    self,
    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 =>
          match result.to_option() {
            Some(v) => callback(Ok(v))
            None => ()
          }
      }
    },
  )
}

///|
#borrow(self_, cancellable)
extern "c" fn g_unix_connection_send_credentials_async(
  self_ : UnixConnection,
  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_unix_connection_send_credentials_async"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.UnixConnection.send_credentials_async.html).
pub fn UnixConnection::send_credentials_async(
  self : UnixConnection,
  cancellable : &ICancellable?,
  callback : (Result[Bool, @glib.Error_]) -> Unit,
) -> Unit {
  g_unix_connection_send_credentials_async(
    self,
    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 IUnixConnection with fn receive_credentials(self, cancellable) -> Credentials raise @glib.Error_ {
  self.as_unix_connection().receive_credentials(cancellable)
}

///|
impl IUnixConnection with fn receive_fd(self, cancellable) -> Int raise @glib.Error_ {
  self.as_unix_connection().receive_fd(cancellable)
}

///|
impl IUnixConnection with fn send_credentials(self, cancellable) -> Bool raise @glib.Error_ {
  self.as_unix_connection().send_credentials(cancellable)
}

///|
impl IUnixConnection with fn send_fd(self, fd, cancellable) -> Bool raise @glib.Error_ {
  self.as_unix_connection().send_fd(fd, cancellable)
}

///|
impl IUnixConnection with fn receive_credentials_async(
  self,
  cancellable,
  callback,
) -> Unit {
  self.as_unix_connection().receive_credentials_async(cancellable, callback)
}

///|
impl IUnixConnection with fn send_credentials_async(self, cancellable, callback) -> Unit {
  self.as_unix_connection().send_credentials_async(cancellable, callback)
}

///|
pub fn UnixConnection::as_socket_connection(
  self : UnixConnection,
) -> SocketConnection = "%identity"

///|
pub impl ISocketConnection for UnixConnection with fn as_socket_connection(self) {
  self.as_socket_connection()
}

///|
pub fn UnixConnection::as_io_stream(self : UnixConnection) -> IOStream = "%identity"

///|
pub impl IIOStream for UnixConnection with fn as_io_stream(self) {
  self.as_io_stream()
}

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

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