Proposal: `subclass` API: use `Result` for functions that can fail
Note: the discussion about this enhancement proposal started here.
In the Rust subclass
API, some functions that can fail return a Result
. Ex.:
-
BaseSrcImpl::create
returnsResult<gst::Buffer, gst::FlowError>
. -
AggregatorImpl::update_src_caps
returnsResult<gst::Caps, gst::FlowError>
.
Other functions retain the bool
return value from the C API.Ex.: start
, set_caps
, …
And other functions return gst::FlowReturn
like the C API. Ex.: BaseSinkImpl::render
, Aggregator::aggregate
, …
As an implementer, functions returning Result
feel more convenient as we can use the facilities such as map
and map_err
and early exit using the ?
operator.
This is a proposal to use Result
for every functions from the subclass
API which can fail. The binding would be in charge of taking care of the required adaptations to conform to the C API. E.g. for BaseSinkImpl::render
, this would be there.
Functions returning a boolean could return Result<(), gst::ErrorMessage>
. This used to be the case for gst-plugin-simple
. In the event of an Err
, the binding could also take care of calling gst_element_message_full
with the GstGError
and optional message
from gst::ErrorMessage
.
Functions returning a gst::FlowReturn
could return Result<gst::FlowSuccess, gst::FlowError>
. The binding would take care of returning GST_FLOW_OK
in case of an Ok(())
result.
Edit: changed return type to Result<gst::FlowSuccess, gst::FlowError>
thanks to @arun's suggestion.