Update various object construction functions to more efficient approaches

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1196>
This commit is contained in:
Sebastian Dröge 2023-01-22 09:48:51 +02:00
parent 38dd1f462b
commit d5e24b9fbd
15 changed files with 304 additions and 392 deletions

View file

@ -400,7 +400,7 @@ mod cairo_compositor {
impl CairoCompositor { impl CairoCompositor {
// Creates a new instance of our compositor with the given name. // Creates a new instance of our compositor with the given name.
pub fn new(name: Option<&str>) -> Self { pub fn new(name: Option<&str>) -> Self {
glib::Object::new(&[("name", &name)]) glib::Object::builder().property("name", name).build()
} }
} }

View file

@ -54,7 +54,7 @@ mod mirror {
impl GLMirrorFilter { impl GLMirrorFilter {
pub fn new(name: Option<&str>) -> Self { pub fn new(name: Option<&str>) -> Self {
glib::Object::new(&[("name", &name)]) glib::Object::builder().property("name", name).build()
} }
} }

View file

@ -154,7 +154,7 @@ mod media_factory {
impl Default for Factory { impl Default for Factory {
// Creates a new instance of our factory // Creates a new instance of our factory
fn default() -> Factory { fn default() -> Factory {
glib::Object::new(&[]) glib::Object::new_default()
} }
} }
} }
@ -266,7 +266,7 @@ mod server {
impl Default for Server { impl Default for Server {
// Creates a new instance of our factory // Creates a new instance of our factory
fn default() -> Server { fn default() -> Server {
glib::Object::new(&[]) glib::Object::new_default()
} }
} }
} }
@ -315,7 +315,7 @@ mod client {
impl Default for Client { impl Default for Client {
// Creates a new instance of our factory // Creates a new instance of our factory
fn default() -> Client { fn default() -> Client {
glib::Object::new(&[]) glib::Object::new_default()
} }
} }
} }
@ -359,7 +359,7 @@ mod mount_points {
impl Default for MountPoints { impl Default for MountPoints {
// Creates a new instance of our factory // Creates a new instance of our factory
fn default() -> Self { fn default() -> Self {
glib::Object::new(&[]) glib::Object::new_default()
} }
} }
} }

View file

@ -216,7 +216,7 @@ mod fir_filter {
impl FirFilter { impl FirFilter {
// Creates a new instance of our filter with the given name // Creates a new instance of our filter with the given name
pub fn new(name: Option<&str>) -> FirFilter { pub fn new(name: Option<&str>) -> FirFilter {
glib::Object::new(&[("name", &name)]) glib::Object::builder().property("name", name).build()
} }
// Sets the coefficients by getting access to the private // Sets the coefficients by getting access to the private

View file

@ -277,7 +277,7 @@ impl AppSink {
/// This method returns an instance of [`AppSinkBuilder`](crate::builders::AppSinkBuilder) which can be used to create [`AppSink`] objects. /// This method returns an instance of [`AppSinkBuilder`](crate::builders::AppSinkBuilder) which can be used to create [`AppSink`] objects.
pub fn builder() -> AppSinkBuilder { pub fn builder() -> AppSinkBuilder {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
AppSinkBuilder::default() AppSinkBuilder::new()
} }
#[doc(alias = "gst_app_sink_set_callbacks")] #[doc(alias = "gst_app_sink_set_callbacks")]
@ -931,100 +931,31 @@ impl AppSink {
} }
} }
#[derive(Default)]
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`AppSink`] objects. /// A [builder-pattern] type to construct [`AppSink`] objects.
/// ///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"] #[must_use = "The builder must be built to be used"]
pub struct AppSinkBuilder { pub struct AppSinkBuilder {
async_: Option<bool>, builder: glib::object::ObjectBuilder<'static, AppSink>,
buffer_list: Option<bool>,
callbacks: Option<AppSinkCallbacks>, callbacks: Option<AppSinkCallbacks>,
caps: Option<gst::Caps>,
drop: Option<bool>,
drop_out_of_segment: Option<bool>, drop_out_of_segment: Option<bool>,
enable_last_sample: Option<bool>,
max_bitrate: Option<u64>,
max_buffers: Option<u32>,
max_lateness: Option<i64>,
#[cfg(any(feature = "v1_16", feature = "dox"))]
processing_deadline: Option<i64>,
qos: Option<bool>,
render_delay: Option<Option<gst::ClockTime>>,
sync: Option<bool>,
throttle_time: Option<u64>,
ts_offset: Option<gst::ClockTimeDiff>,
wait_on_eos: Option<bool>,
name: Option<String>,
} }
impl AppSinkBuilder { impl AppSinkBuilder {
// rustdoc-stripper-ignore-next fn new() -> Self {
/// Create a new [`AppSinkBuilder`]. Self {
pub fn new() -> Self { builder: glib::Object::builder(),
Self::default() callbacks: None,
drop_out_of_segment: None,
}
} }
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// Build the [`AppSink`]. /// Build the [`AppSink`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"] #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> AppSink { pub fn build(self) -> AppSink {
let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; let appsink = self.builder.build();
if let Some(ref async_) = self.async_ {
properties.push(("async", async_));
}
if let Some(ref buffer_list) = self.buffer_list {
properties.push(("buffer-list", buffer_list));
}
if let Some(ref caps) = self.caps {
properties.push(("caps", caps));
}
if let Some(ref drop) = self.drop {
properties.push(("drop", drop));
}
if let Some(ref enable_last_sample) = self.enable_last_sample {
properties.push(("enable-last-sample", enable_last_sample));
}
if let Some(ref max_bitrate) = self.max_bitrate {
properties.push(("max-bitrate", max_bitrate));
}
if let Some(ref max_buffers) = self.max_buffers {
properties.push(("max-buffers", max_buffers));
}
if let Some(ref max_lateness) = self.max_lateness {
properties.push(("max-lateness", max_lateness));
}
#[cfg(any(feature = "v1_16", feature = "dox"))]
if let Some(ref processing_deadline) = self.processing_deadline {
properties.push(("processing-deadline", processing_deadline));
}
if let Some(ref qos) = self.qos {
properties.push(("qos", qos));
}
if let Some(ref render_delay) = self.render_delay {
properties.push(("render-delay", render_delay));
}
if let Some(ref sync) = self.sync {
properties.push(("sync", sync));
}
if let Some(ref throttle_time) = self.throttle_time {
properties.push(("throttle-time", throttle_time));
}
if let Some(ref ts_offset) = self.ts_offset {
properties.push(("ts-offset", ts_offset));
}
if let Some(ref qos) = self.qos {
properties.push(("qos", qos));
}
if let Some(ref wait_on_eos) = self.wait_on_eos {
properties.push(("wait-on-eos", wait_on_eos));
}
if let Some(ref name) = self.name {
properties.push(("name", name));
}
let appsink = glib::Object::new::<AppSink>(&properties);
if let Some(callbacks) = self.callbacks { if let Some(callbacks) = self.callbacks {
appsink.set_callbacks(callbacks); appsink.set_callbacks(callbacks);
@ -1037,96 +968,138 @@ impl AppSinkBuilder {
appsink appsink
} }
pub fn async_(mut self, async_: bool) -> Self { pub fn async_(self, async_: bool) -> Self {
self.async_ = Some(async_); Self {
self builder: self.builder.property("async", async_),
..self
}
} }
pub fn buffer_list(mut self, buffer_list: bool) -> Self { pub fn buffer_list(self, buffer_list: bool) -> Self {
self.buffer_list = Some(buffer_list); Self {
self builder: self.builder.property("buffer-list", buffer_list),
..self
}
} }
pub fn callbacks(mut self, callbacks: AppSinkCallbacks) -> Self { pub fn callbacks(self, callbacks: AppSinkCallbacks) -> Self {
self.callbacks = Some(callbacks); Self {
self callbacks: Some(callbacks),
..self
}
} }
pub fn caps(mut self, caps: &gst::Caps) -> Self { pub fn caps(self, caps: &gst::Caps) -> Self {
self.caps = Some(caps.clone()); Self {
self builder: self.builder.property("caps", caps),
..self
}
} }
pub fn drop(mut self, drop: bool) -> Self { pub fn drop(self, drop: bool) -> Self {
self.drop = Some(drop); Self {
self builder: self.builder.property("drop", drop),
..self
}
} }
pub fn drop_out_of_segment(mut self, drop_out_of_segment: bool) -> Self { pub fn drop_out_of_segment(self, drop_out_of_segment: bool) -> Self {
self.drop_out_of_segment = Some(drop_out_of_segment); Self {
self builder: self
.builder
.property("drop-out-of-segment", drop_out_of_segment),
..self
}
} }
pub fn enable_last_sample(mut self, enable_last_sample: bool) -> Self { pub fn enable_last_sample(self, enable_last_sample: bool) -> Self {
self.enable_last_sample = Some(enable_last_sample); Self {
self builder: self
.builder
.property("enable-last-sample", enable_last_sample),
..self
}
} }
pub fn max_bitrate(mut self, max_bitrate: u64) -> Self { pub fn max_bitrate(self, max_bitrate: u64) -> Self {
self.max_bitrate = Some(max_bitrate); Self {
self builder: self.builder.property("max-bitrate", max_bitrate),
..self
}
} }
pub fn max_buffers(mut self, max_buffers: u32) -> Self { pub fn max_buffers(self, max_buffers: u32) -> Self {
self.max_buffers = Some(max_buffers); Self {
self builder: self.builder.property("max-buffers", max_buffers),
..self
}
} }
pub fn max_lateness(mut self, max_lateness: i64) -> Self { pub fn max_lateness(self, max_lateness: i64) -> Self {
self.max_lateness = Some(max_lateness); Self {
self builder: self.builder.property("max-lateness", max_lateness),
..self
}
} }
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub fn processing_deadline(mut self, processing_deadline: i64) -> Self { pub fn processing_deadline(self, processing_deadline: i64) -> Self {
self.processing_deadline = Some(processing_deadline); Self {
self builder: self
.builder
.property("processing-deadline", processing_deadline),
..self
}
} }
pub fn qos(mut self, qos: bool) -> Self { pub fn qos(self, qos: bool) -> Self {
self.qos = Some(qos); Self {
self builder: self.builder.property("qos", qos),
..self
}
} }
pub fn render_delay(mut self, render_delay: Option<gst::ClockTime>) -> Self { pub fn render_delay(self, render_delay: Option<gst::ClockTime>) -> Self {
self.render_delay = Some(render_delay); Self {
self builder: self.builder.property("render-delay", render_delay),
..self
}
} }
pub fn sync(mut self, sync: bool) -> Self { pub fn sync(self, sync: bool) -> Self {
self.sync = Some(sync); Self {
self builder: self.builder.property("sync", sync),
..self
}
} }
pub fn throttle_time(mut self, throttle_time: u64) -> Self { pub fn throttle_time(self, throttle_time: u64) -> Self {
self.throttle_time = Some(throttle_time); Self {
self builder: self.builder.property("throttle-time", throttle_time),
..self
}
} }
pub fn ts_offset(mut self, ts_offset: gst::ClockTimeDiff) -> Self { pub fn ts_offset(self, ts_offset: gst::ClockTimeDiff) -> Self {
self.ts_offset = Some(ts_offset); Self {
self builder: self.builder.property("ts-offset", ts_offset),
..self
}
} }
pub fn wait_on_eos(mut self, wait_on_eos: bool) -> Self { pub fn wait_on_eos(self, wait_on_eos: bool) -> Self {
self.wait_on_eos = Some(wait_on_eos); Self {
self builder: self.builder.property("wait_on_eos", wait_on_eos),
..self
}
} }
pub fn name(mut self, name: &str) -> Self { pub fn name(self, name: impl Into<glib::GString>) -> Self {
self.name = Some(name.to_string()); Self {
self builder: self.builder.property("name", name.into()),
..self
}
} }
} }

View file

@ -218,7 +218,7 @@ impl AppSrc {
/// This method returns an instance of [`AppSrcBuilder`](crate::builders::AppSrcBuilder) which can be used to create [`AppSrc`] objects. /// This method returns an instance of [`AppSrcBuilder`](crate::builders::AppSrcBuilder) which can be used to create [`AppSrc`] objects.
pub fn builder() -> AppSrcBuilder { pub fn builder() -> AppSrcBuilder {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
AppSrcBuilder::default() AppSrcBuilder::new()
} }
#[doc(alias = "gst_app_src_set_callbacks")] #[doc(alias = "gst_app_src_set_callbacks")]
@ -353,111 +353,31 @@ impl AppSrc {
} }
} }
#[derive(Default)]
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`AppSrc`] objects. /// A [builder-pattern] type to construct [`AppSrc`] objects.
/// ///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"] #[must_use = "The builder must be built to be used"]
pub struct AppSrcBuilder { pub struct AppSrcBuilder {
automatic_eos: Option<bool>, builder: glib::object::ObjectBuilder<'static, AppSrc>,
block: Option<bool>,
callbacks: Option<AppSrcCallbacks>, callbacks: Option<AppSrcCallbacks>,
caps: Option<gst::Caps>, automatic_eos: Option<bool>,
do_timestamp: Option<bool>,
duration: Option<u64>,
format: Option<gst::Format>,
#[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
handle_segment_change: Option<bool>,
is_live: Option<bool>,
#[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
leaky_type: Option<crate::AppLeakyType>,
#[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
max_buffers: Option<u64>,
max_bytes: Option<u64>,
max_latency: Option<i64>,
#[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
max_time: Option<Option<gst::ClockTime>>,
min_latency: Option<i64>,
min_percent: Option<u32>,
size: Option<i64>,
stream_type: Option<crate::AppStreamType>,
name: Option<String>,
} }
impl AppSrcBuilder { impl AppSrcBuilder {
// rustdoc-stripper-ignore-next fn new() -> Self {
/// Create a new [`AppSrcBuilder`]. Self {
pub fn new() -> Self { builder: glib::Object::builder(),
Self::default() callbacks: None,
automatic_eos: None,
}
} }
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// Build the [`AppSrc`]. /// Build the [`AppSrc`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"] #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> AppSrc { pub fn build(self) -> AppSrc {
let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; let appsrc = self.builder.build();
if let Some(ref block) = self.block {
properties.push(("block", block));
}
if let Some(ref caps) = self.caps {
properties.push(("caps", caps));
}
if let Some(ref do_timestamp) = self.do_timestamp {
properties.push(("do-timestamp", do_timestamp));
}
if let Some(ref duration) = self.duration {
properties.push(("duration", duration));
}
if let Some(ref format) = self.format {
properties.push(("format", format));
}
#[cfg(any(feature = "v1_18", feature = "dox"))]
if let Some(ref handle_segment_change) = self.handle_segment_change {
properties.push(("handle-segment-change", handle_segment_change));
}
if let Some(ref is_live) = self.is_live {
properties.push(("is-live", is_live));
}
#[cfg(any(feature = "v1_20", feature = "dox"))]
if let Some(ref leaky_type) = self.leaky_type {
properties.push(("leaky-type", leaky_type));
}
#[cfg(any(feature = "v1_20", feature = "dox"))]
if let Some(ref max_buffers) = self.max_buffers {
properties.push(("max-buffers", max_buffers));
}
if let Some(ref max_bytes) = self.max_bytes {
properties.push(("max-bytes", max_bytes));
}
if let Some(ref max_latency) = self.max_latency {
properties.push(("max-latency", max_latency));
}
#[cfg(any(feature = "v1_20", feature = "dox"))]
if let Some(ref max_time) = self.max_time {
properties.push(("max-time", max_time));
}
if let Some(ref min_latency) = self.min_latency {
properties.push(("min-latency", min_latency));
}
if let Some(ref min_percent) = self.min_percent {
properties.push(("min-percent", min_percent));
}
if let Some(ref size) = self.size {
properties.push(("size", size));
}
if let Some(ref stream_type) = self.stream_type {
properties.push(("stream-type", stream_type));
}
if let Some(ref name) = self.name {
properties.push(("name", name));
}
let appsrc = glib::Object::new::<AppSrc>(&properties);
if let Some(callbacks) = self.callbacks { if let Some(callbacks) = self.callbacks {
appsrc.set_callbacks(callbacks); appsrc.set_callbacks(callbacks);
@ -470,107 +390,147 @@ impl AppSrcBuilder {
appsrc appsrc
} }
pub fn automatic_eos(mut self, automatic_eos: bool) -> Self { pub fn automatic_eos(self, automatic_eos: bool) -> Self {
self.automatic_eos = Some(automatic_eos); Self {
self automatic_eos: Some(automatic_eos),
..self
}
} }
pub fn block(mut self, block: bool) -> Self { pub fn block(self, block: bool) -> Self {
self.block = Some(block); Self {
self builder: self.builder.property("block", block),
..self
}
} }
pub fn callbacks(mut self, callbacks: AppSrcCallbacks) -> Self { pub fn callbacks(self, callbacks: AppSrcCallbacks) -> Self {
self.callbacks = Some(callbacks); Self {
self callbacks: Some(callbacks),
..self
}
} }
pub fn caps(mut self, caps: &gst::Caps) -> Self { pub fn caps(self, caps: &gst::Caps) -> Self {
self.caps = Some(caps.clone()); Self {
self builder: self.builder.property("caps", caps),
..self
}
} }
pub fn do_timestamp(mut self, do_timestamp: bool) -> Self { pub fn do_timestamp(self, do_timestamp: bool) -> Self {
self.do_timestamp = Some(do_timestamp); Self {
self builder: self.builder.property("do-timestamp", do_timestamp),
..self
}
} }
pub fn duration(mut self, duration: u64) -> Self { pub fn duration(self, duration: u64) -> Self {
self.duration = Some(duration); Self {
self builder: self.builder.property("duration", duration),
..self
}
} }
pub fn format(mut self, format: gst::Format) -> Self { pub fn format(self, format: gst::Format) -> Self {
self.format = Some(format); Self {
self builder: self.builder.property("format", format),
..self
}
} }
#[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
pub fn handle_segment_change(mut self, handle_segment_change: bool) -> Self { pub fn handle_segment_change(self, handle_segment_change: bool) -> Self {
self.handle_segment_change = Some(handle_segment_change); Self {
self builder: self
.builder
.property("handle-segment-change", handle_segment_change),
..self
}
} }
pub fn is_live(mut self, is_live: bool) -> Self { pub fn is_live(self, is_live: bool) -> Self {
self.is_live = Some(is_live); Self {
self builder: self.builder.property("is-live", is_live),
..self
}
} }
#[cfg(any(feature = "v1_20", feature = "dox"))] #[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
pub fn leaky_type(mut self, leaky_type: crate::AppLeakyType) -> Self { pub fn leaky_type(self, leaky_type: crate::AppLeakyType) -> Self {
self.leaky_type = Some(leaky_type); Self {
self builder: self.builder.property("leaky-type", leaky_type),
..self
}
} }
#[cfg(any(feature = "v1_20", feature = "dox"))] #[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
pub fn max_buffers(mut self, max_buffers: u64) -> Self { pub fn max_buffers(self, max_buffers: u64) -> Self {
self.max_buffers = Some(max_buffers); Self {
self builder: self.builder.property("max-buffers", max_buffers),
..self
}
} }
pub fn max_bytes(mut self, max_bytes: u64) -> Self { pub fn max_bytes(self, max_bytes: u64) -> Self {
self.max_bytes = Some(max_bytes); Self {
self builder: self.builder.property("max-bytes", max_bytes),
..self
}
} }
pub fn max_latency(mut self, max_latency: i64) -> Self { pub fn max_latency(self, max_latency: i64) -> Self {
self.max_latency = Some(max_latency); Self {
self builder: self.builder.property("max-latency", max_latency),
..self
}
} }
#[cfg(any(feature = "v1_20", feature = "dox"))] #[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
pub fn max_time(mut self, max_time: Option<gst::ClockTime>) -> Self { pub fn max_time(self, max_time: Option<gst::ClockTime>) -> Self {
self.max_time = Some(max_time); Self {
self builder: self.builder.property("max-time", max_time),
..self
}
} }
pub fn min_latency(mut self, min_latency: i64) -> Self { pub fn min_latency(self, min_latency: i64) -> Self {
self.min_latency = Some(min_latency); Self {
self builder: self.builder.property("min-latency", min_latency),
..self
}
} }
pub fn min_percent(mut self, min_percent: u32) -> Self { pub fn min_percent(self, min_percent: u32) -> Self {
self.min_percent = Some(min_percent); Self {
self builder: self.builder.property("min-percent", min_percent),
..self
}
} }
pub fn size(mut self, size: i64) -> Self { pub fn size(self, size: i64) -> Self {
self.size = Some(size); Self {
self builder: self.builder.property("size", size),
..self
}
} }
pub fn stream_type(mut self, stream_type: crate::AppStreamType) -> Self { pub fn stream_type(self, stream_type: crate::AppStreamType) -> Self {
self.stream_type = Some(stream_type); Self {
self builder: self.builder.property("stream-type", stream_type),
..self
}
} }
pub fn name(mut self, name: &str) -> Self { pub fn name(self, name: impl Into<glib::GString>) -> Self {
self.name = Some(name.to_string()); Self {
self builder: self.builder.property("name", name.into()),
..self
}
} }
} }

View file

@ -17,7 +17,7 @@ impl Bin {
/// ///
/// This method returns an instance of [`BinBuilder`](crate::builders::BinBuilder) which can be used to create [`Bin`] objects. /// This method returns an instance of [`BinBuilder`](crate::builders::BinBuilder) which can be used to create [`Bin`] objects.
pub fn builder() -> BinBuilder { pub fn builder() -> BinBuilder {
BinBuilder::default() BinBuilder::new()
} }
} }
@ -223,59 +223,49 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
impl Default for Bin { impl Default for Bin {
fn default() -> Self { fn default() -> Self {
glib::object::Object::new::<Self>(&[]) glib::object::Object::new_default()
} }
} }
#[derive(Clone, Default)]
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`Bin`] objects. /// A [builder-pattern] type to construct [`Bin`] objects.
/// ///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"] #[must_use = "The builder must be built to be used"]
pub struct BinBuilder { pub struct BinBuilder {
async_handling: Option<bool>, builder: glib::object::ObjectBuilder<'static, Bin>,
message_forward: Option<bool>,
name: Option<String>,
} }
impl BinBuilder { impl BinBuilder {
// rustdoc-stripper-ignore-next fn new() -> Self {
/// Create a new [`BinBuilder`]. Self {
pub fn new() -> Self { builder: glib::Object::builder(),
Self::default() }
} }
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// Build the [`Bin`]. /// Build the [`Bin`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"] #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> Bin { pub fn build(self) -> Bin {
let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; self.builder.build()
if let Some(ref async_handling) = self.async_handling {
properties.push(("async-handling", async_handling));
}
if let Some(ref message_forward) = self.message_forward {
properties.push(("message-forward", message_forward));
}
if let Some(ref name) = self.name {
properties.push(("name", name));
}
glib::Object::new::<Bin>(&properties)
} }
pub fn async_handling(mut self, async_handling: bool) -> Self { pub fn async_handling(self, async_handling: bool) -> Self {
self.async_handling = Some(async_handling); Self {
self builder: self.builder.property("async-handling", async_handling),
}
} }
pub fn message_forward(mut self, message_forward: bool) -> Self { pub fn message_forward(self, message_forward: bool) -> Self {
self.message_forward = Some(message_forward); Self {
self builder: self.builder.property("message-forward", message_forward),
}
} }
pub fn name(mut self, name: &str) -> Self { pub fn name(self, name: impl Into<glib::GString>) -> Self {
self.name = Some(name.to_string()); Self {
self builder: self.builder.property("name", name.into()),
}
} }
} }

View file

@ -48,7 +48,7 @@ impl ElementFactory {
ElementBuilder { ElementBuilder {
name_or_factory: NameOrFactory::Factory(self), name_or_factory: NameOrFactory::Factory(self),
properties: Vec::new(), properties: smallvec::SmallVec::new(),
} }
} }
@ -60,7 +60,7 @@ impl ElementFactory {
ElementBuilder { ElementBuilder {
name_or_factory: NameOrFactory::Name(factoryname), name_or_factory: NameOrFactory::Name(factoryname),
properties: Vec::new(), properties: smallvec::SmallVec::new(),
} }
} }
@ -219,7 +219,7 @@ impl ElementFactory {
#[must_use = "The builder must be built to be used"] #[must_use = "The builder must be built to be used"]
pub struct ElementBuilder<'a> { pub struct ElementBuilder<'a> {
name_or_factory: NameOrFactory<'a>, name_or_factory: NameOrFactory<'a>,
properties: Vec<(&'a str, ValueOrStr<'a>)>, properties: smallvec::SmallVec<[(&'a str, ValueOrStr<'a>); 16]>,
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
@ -236,12 +236,14 @@ enum ValueOrStr<'a> {
impl<'a> ElementBuilder<'a> { impl<'a> ElementBuilder<'a> {
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// Sets the name property to the given `name`. /// Sets the name property to the given `name`.
pub fn name(self, name: &'a str) -> Self { #[inline]
self.property("name", name) pub fn name(self, name: impl Into<glib::GString>) -> Self {
self.property("name", name.into())
} }
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// Set property `name` to the given value `value`. /// Set property `name` to the given value `value`.
#[inline]
pub fn property(self, name: &'a str, value: impl Into<glib::Value> + 'a) -> Self { pub fn property(self, name: &'a str, value: impl Into<glib::Value> + 'a) -> Self {
Self { Self {
name_or_factory: self.name_or_factory, name_or_factory: self.name_or_factory,
@ -255,6 +257,7 @@ impl<'a> ElementBuilder<'a> {
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// Set property `name` to the given string value `value`. /// Set property `name` to the given string value `value`.
#[inline]
pub fn property_from_str(self, name: &'a str, value: &'a str) -> Self { pub fn property_from_str(self, name: &'a str, value: &'a str) -> Self {
Self { Self {
name_or_factory: self.name_or_factory, name_or_factory: self.name_or_factory,
@ -328,7 +331,7 @@ impl<'a> ElementBuilder<'a> {
)); ));
} }
let mut properties = Vec::with_capacity(self.properties.len()); let mut properties = smallvec::SmallVec::<[_; 16]>::with_capacity(self.properties.len());
let klass = glib::Class::<Element>::from_type(element_type).unwrap(); let klass = glib::Class::<Element>::from_type(element_type).unwrap();
for (name, value) in self.properties { for (name, value) in self.properties {
match value { match value {
@ -386,9 +389,10 @@ impl<'a> ElementBuilder<'a> {
} }
} }
let element = glib::Object::with_values(element_type, &properties) let element = unsafe {
.downcast::<crate::Element>() glib::Object::with_mut_values(element_type, &mut properties)
.unwrap(); .unsafe_cast::<crate::Element>()
};
unsafe { unsafe {
use std::sync::atomic; use std::sync::atomic;

View file

@ -1617,7 +1617,10 @@ impl<T: IsA<Pad> + IsA<glib::Object> + glib::object::IsClass> PadBuilder<T> {
pub fn new(name: Option<&str>, direction: crate::PadDirection) -> Self { pub fn new(name: Option<&str>, direction: crate::PadDirection) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let pad = glib::Object::new::<T>(&[("name", &name), ("direction", &direction)]); let pad = glib::Object::builder::<T>()
.property("name", name)
.property("direction", direction)
.build();
// Ghost pads are a bit special // Ghost pads are a bit special
if let Some(pad) = pad.dynamic_cast_ref::<crate::GhostPad>() { if let Some(pad) = pad.dynamic_cast_ref::<crate::GhostPad>() {
@ -1660,16 +1663,14 @@ impl<T: IsA<Pad> + IsA<glib::Object> + glib::object::IsClass> PadBuilder<T> {
} }
} }
let pad = glib::Object::with_type( let mut properties = [
type_, ("name", name.map(glib::GString::from).into()),
&[ ("direction", templ.direction().into()),
("name", &name), ("template", templ.into()),
("direction", &templ.direction()), ];
("template", templ),
], let pad =
) unsafe { glib::Object::with_mut_values(type_, &mut properties).unsafe_cast::<T>() };
.downcast::<T>()
.unwrap();
// Ghost pads are a bit special // Ghost pads are a bit special
if let Some(pad) = pad.dynamic_cast_ref::<crate::GhostPad>() { if let Some(pad) = pad.dynamic_cast_ref::<crate::GhostPad>() {

View file

@ -10,7 +10,7 @@ impl Pipeline {
/// ///
/// This method returns an instance of [`PipelineBuilder`](crate::builders::PipelineBuilder) which can be used to create [`Pipeline`] objects. /// This method returns an instance of [`PipelineBuilder`](crate::builders::PipelineBuilder) which can be used to create [`Pipeline`] objects.
pub fn builder() -> PipelineBuilder { pub fn builder() -> PipelineBuilder {
PipelineBuilder::default() PipelineBuilder::new()
} }
} }
@ -51,85 +51,66 @@ impl<O: IsA<crate::Pipeline>> GstPipelineExtManual for O {
impl Default for Pipeline { impl Default for Pipeline {
fn default() -> Self { fn default() -> Self {
glib::object::Object::new::<Self>(&[]) glib::object::Object::new_default()
} }
} }
#[derive(Clone, Default)]
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`Pipeline`] objects. /// A [builder-pattern] type to construct [`Pipeline`] objects.
/// ///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"] #[must_use = "The builder must be built to be used"]
pub struct PipelineBuilder { pub struct PipelineBuilder {
auto_flush_bus: Option<bool>, builder: glib::object::ObjectBuilder<'static, Pipeline>,
delay: Option<u64>,
latency: Option<u64>,
async_handling: Option<bool>,
message_forward: Option<bool>,
name: Option<String>,
} }
impl PipelineBuilder { impl PipelineBuilder {
// rustdoc-stripper-ignore-next fn new() -> Self {
/// Create a new [`PipelineBuilder`]. Self {
pub fn new() -> Self { builder: glib::Object::builder(),
Self::default() }
} }
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// Build the [`Pipeline`]. /// Build the [`Pipeline`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"] #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> Pipeline { pub fn build(self) -> Pipeline {
let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; self.builder.build()
if let Some(ref auto_flush_bus) = self.auto_flush_bus {
properties.push(("auto-flush-bus", auto_flush_bus));
}
if let Some(ref delay) = self.delay {
properties.push(("delay", delay));
}
if let Some(ref latency) = self.latency {
properties.push(("latency", latency));
}
if let Some(ref async_handling) = self.async_handling {
properties.push(("async-handling", async_handling));
}
if let Some(ref message_forward) = self.message_forward {
properties.push(("message-forward", message_forward));
}
if let Some(ref name) = self.name {
properties.push(("name", name));
}
glib::Object::new::<Pipeline>(&properties)
} }
pub fn auto_flush_bus(mut self, auto_flush_bus: bool) -> Self { pub fn auto_flush_bus(self, auto_flush_bus: bool) -> Self {
self.auto_flush_bus = Some(auto_flush_bus); Self {
self builder: self.builder.property("auto-flush-bus", auto_flush_bus),
}
} }
pub fn delay(mut self, delay: u64) -> Self { pub fn delay(self, delay: u64) -> Self {
self.delay = Some(delay); Self {
self builder: self.builder.property("delay", delay),
}
} }
pub fn latency(mut self, latency: u64) -> Self { pub fn latency(self, latency: crate::ClockTime) -> Self {
self.latency = Some(latency); Self {
self builder: self.builder.property("latency", latency),
}
} }
pub fn async_handling(mut self, async_handling: bool) -> Self { pub fn async_handling(self, async_handling: bool) -> Self {
self.async_handling = Some(async_handling); Self {
self builder: self.builder.property("async-handling", async_handling),
}
} }
pub fn message_forward(mut self, message_forward: bool) -> Self { pub fn message_forward(self, message_forward: bool) -> Self {
self.message_forward = Some(message_forward); Self {
self builder: self.builder.property("message-forward", message_forward),
}
} }
pub fn name(mut self, name: &str) -> Self { pub fn name(self, name: impl Into<glib::GString>) -> Self {
self.name = Some(name.to_string()); Self {
self builder: self.builder.property("name", name.into()),
}
} }
} }

View file

@ -150,7 +150,7 @@ mod tests {
impl Default for TestAllocator { impl Default for TestAllocator {
fn default() -> Self { fn default() -> Self {
glib::Object::new(&[]) glib::Object::new_default()
} }
} }

View file

@ -517,7 +517,7 @@ mod tests {
impl Default for TestBufferPool { impl Default for TestBufferPool {
fn default() -> Self { fn default() -> Self {
glib::Object::new(&[]) glib::Object::new_default()
} }
} }

View file

@ -708,7 +708,7 @@ mod tests {
impl TestElement { impl TestElement {
pub fn new(name: Option<&str>) -> Self { pub fn new(name: Option<&str>) -> Self {
glib::Object::new(&[("name", &name)]) glib::Object::builder().property("name", name).build()
} }
} }

View file

@ -126,7 +126,10 @@ mod tests {
impl TestPad { impl TestPad {
pub fn new(name: &str, direction: PadDirection) -> Self { pub fn new(name: &str, direction: PadDirection) -> Self {
glib::Object::new(&[("name", &name), ("direction", &direction)]) glib::Object::builder()
.property("name", name)
.property("direction", direction)
.build()
} }
} }

View file

@ -306,7 +306,7 @@ mod tests {
impl Default for TestPool { impl Default for TestPool {
fn default() -> Self { fn default() -> Self {
glib::Object::new(&[]) glib::Object::new_default()
} }
} }