gtk-rs / gir

Tool to generate rust bindings and user API for glib-based libraries
https://gtk-rs.org/gir/book/
MIT License
225 stars 98 forks source link

codegen/function: body future handles ownership of slice argument #1580

Open BiagioFesta opened 3 weeks ago

BiagioFesta commented 3 weeks ago

Currently, the future body generated is something like:

pub fn probe_endpoints_future(
    my_slice: &[MyObject],
) -> Pin<
    Box_<dyn std::future::Future<Output = Result<_, glib::Error>> + 'static>,
> {
    skip_assert_initialized!();

   let my_slice = my_slice.map(ToOwned::to_owned);   // if my_slice is declared as nullable
             // or
   let my_slice = my_slice.clone();                  // if my_slice is not declared as nullable

    Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| {
      // ...
}

both approaches fail to compile as:

This PR aims to handle the case of slice argument

BiagioFesta commented 3 weeks ago

CI is failing, but I don't think it is related with the changes:

Resolving github.com (github.com)... 140.82.116.4
Connecting to github.com (github.com)|140.82.116.4|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2024-06-12 15:30:35 ERROR 404: Not Found