This repository has been archived by the owner on Jun 8, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
312e5fa
commit 0215a3d
Showing
2 changed files
with
19 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
GuillaumeGomez
Author
Member
|
||
} | ||
|
||
#[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!(); | ||
|
@@ -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(); | ||
|
Usually we put the Sized requirement on the trait directly