Skip to content

Add field_if_some setter for builders

This commit adds _if_some() variants for builder field setters. The variants aim at improving usability when setting optional fields. E.g. currently, we need to write something like:

let opt_value = ...;
let mut sb = gst::Structure::builder("test")
    .field("mandatory_field", "mandatory");

if let Some(value) = opt_value
    sb = sb.field("optional_field", value);
}

let s = sb.build();

With _if_some(), this can be written like this:

let opt_value = ...;
let s = gst::Structure::builder("test")
    .field("mandatory_field", "mandatory")
    .field_if_some("optional_field", opt_value)
    .build();

Fixes: #499 (closed)

Merge request reports

Loading