Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
New wave of updates
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jun 25, 2018
1 parent 312e5fa commit 0215a3d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
3 changes: 0 additions & 3 deletions Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,6 @@ status = "generate"
[[object.function]]
name = "communicate_utf8_async"
ignore = true
[[object.function]]
name = "communicate_utf8_async_future"
ignore = true

[[object]]
name = "Gio.SubprocessLauncher"
Expand Down
26 changes: 19 additions & 7 deletions src/subprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,44 @@ use Subprocess;
use Cancellable;
#[cfg(any(feature = "v2_40", feature = "dox"))]
use Error;
#[cfg(any(feature = "v2_40", feature = "dox"))]
use ffi;
#[cfg(any(feature = "v2_40", feature = "dox"))]
use glib;
#[cfg(any(feature = "v2_40", feature = "dox"))]
use glib::object::IsA;
#[cfg(any(feature = "v2_40", feature = "dox"))]
use glib::translate::*;
#[cfg(any(feature = "v2_40", feature = "dox"))]
use glib_ffi;
#[cfg(any(feature = "v2_40", feature = "dox"))]
use gobject_ffi;
#[cfg(any(feature = "v2_40", feature = "dox"))]
use std::ptr;
#[cfg(feature = "futures")]
use futures_core;
#[cfg(feature = "futures")]
use std::boxed::Box as Box_;

pub trait SubprocessExtManual {
#[cfg(any(feature = "v2_40", feature = "dox"))]
fn communicate_utf8_async<'a, P: Into<Option<String>>, Q: Into<Option<&'a Cancellable>>, R: FnOnce(Result<(String, String), Error>) + Send + 'static>(&self, stdin_buf: P, cancellable: Q, callback: R);

#[cfg(feature = "futures")]
#[cfg(any(feature = "v2_40", feature = "dox"))]
fn communicate_utf8_async_future<P: Into<Option<String>>>(&self, stdin_buf: P) -> Box_<futures_core::Future<Item = (Self, (String, String)), Error = (Self, Error)>>;
fn communicate_utf8_async_future<P: Into<Option<String>>>(&self, stdin_buf: P) -> Box_<futures_core::Future<Item = (Self, (String, String)), Error = (Self, Error)>>
where Self: Sized;

This comment has been minimized.

Copy link
@sdroege

sdroege Jun 25, 2018

Member

Usually we put the Sized requirement on the trait directly

This comment has been minimized.

Copy link
@GuillaumeGomez

GuillaumeGomez Jun 25, 2018

Author Member

At this point, I just improvised haha. Do you want me to move it? While we're at it...

This comment has been minimized.

Copy link
@sdroege

sdroege Jun 25, 2018

Member

Doesn't really make a difference :) just for consistency maybe

This comment has been minimized.

Copy link
@GuillaumeGomez

GuillaumeGomez Jun 25, 2018

Author Member

Then here I come (I'll squash this commit then).

}

#[cfg(any(feature = "v2_40", feature = "dox"))]
impl<O: IsA<Subprocess> + IsA<glib::object::Object> + Clone + 'static> SubprocessExtManual for O {
#[cfg(any(feature = "v2_40", feature = "dox"))]
fn communicate_utf8_async<'a, P: Into<Option<String>>, Q: Into<Option<&'a Cancellable>>, R: FnOnce(Result<(String, String), Error>) + Send + 'static>(&self, stdin_buf: P, cancellable: Q, callback: R) {
let stdin_buf = stdin_buf.into();
let stdin_buf = stdin_buf.to_glib_none();
let stdin_buf = stdin_buf.to_glib_full();
let cancellable = cancellable.into();
let cancellable = cancellable.to_glib_none();
let user_data: Box<Box<(R, *mut i8)>> = Box::new(Box::new((callback, stdin_buf.0)));
let user_data: Box<Box<(R, *mut i8)>> = Box::new(Box::new((callback, stdin_buf)));
unsafe extern "C" fn communicate_utf8_async_trampoline<R: FnOnce(Result<(String, String), Error>) + Send + 'static>(_source_object: *mut gobject_ffi::GObject, res: *mut ffi::GAsyncResult, user_data: glib_ffi::gpointer)
{
callback_guard!();
Expand All @@ -44,24 +56,24 @@ impl<O: IsA<Subprocess> + IsA<glib::object::Object> + Clone + 'static> Subproces
}
let callback = communicate_utf8_async_trampoline::<R>;
unsafe {
ffi::g_subprocess_communicate_utf8_async(self.to_glib_none().0, stdin_buf.0, cancellable.0, Some(callback), Box::into_raw(user_data) as *mut _);
ffi::g_subprocess_communicate_utf8_async(self.to_glib_none().0, stdin_buf, cancellable.0, Some(callback), Box::into_raw(user_data) as *mut _);
}
}

#[cfg(feature = "futures")]
#[cfg(any(feature = "v2_40", feature = "dox"))]
fn communicate_utf8_async_future<P: Into<Option<String>>>(&self, stdin_buf: P) -> Box_<futures_core::Future<Item = (Self, (String, String)), Error = (Self, Error)>> {
fn communicate_utf8_async_future<P: Into<Option<String>>>(&self, stdin_buf: P) -> Box_<futures_core::Future<Item = (Self, (String, String)), Error = (Self, Error)>>
where Self: Sized {
use GioFuture;
use send_cell::SendCell;

let stdin_buf = stdin_buf.into();
let stdin_buf = stdin_buf.map(ToOwned::to_owned);
GioFuture::new(self, move |obj, send| {
let cancellable = Cancellable::new();
let send = SendCell::new(send);
let obj_clone = SendCell::new(obj.clone());
obj.communicate_utf8_async(
stdin_buf.as_ref().map(::std::borrow::Borrow::borrow),
stdin_buf,
Some(&cancellable),
move |res| {
let obj = obj_clone.into_inner();
Expand Down

0 comments on commit 0215a3d

Please sign in to comment.