Skip to content

Draft: Use `imp Into<Option<_>>` in argument position as much as possible

This allows users to call the corresponding functions without the need to embed the argument in Some(_).

I applied this approach to manual code and I moved Bin::new and Pipeline::new to manual code to implement it too there. Many auto functions could take advantage of this but that would require a gir evolution. We could probably apply this to App{Sink,Src}::set_caps manually though.

See the result in the examples and in this (WIP) gst-plugins-rs branch: https://gitlab.freedesktop.org/fengalin/gst-plugins-rs/-/tree/nullability-into-option-args

When the user wants to pass None, most of the time, the compiler is able to infer the type:

    let buf = pool.acquire_buffer(None).unwrap();

However, when the function uses a trait bound for the optional argument type, user must disambiguate the type. Ex.:

    alloc_query.add_allocation_pool::<gst::BufferPool>(None, 1024, 1, 4);

For most types, the NONE constant is also available:

    alloc_query.add_allocation_pool(gst::BufferPool::NONE, 1024, 1, 4);
Edited by François Laignel

Merge request reports

Loading