gstreamer,video: Do not zero-initialize designated struct members

This should be analogous to C struct initalizers where all unspecified
fields are initialized to zero. Without mut this reads a bit nicer as
well.

Note that two out of three structs have all members specified, hence
need no zero-initialization of the remainder at all.
This commit is contained in:
Marijn Suijten 2021-01-10 14:30:58 +01:00
parent 89c7883202
commit ce67076f26
3 changed files with 18 additions and 27 deletions

View file

@ -59,16 +59,12 @@ impl VideoAlignment {
) -> Self { ) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let videoalignment = unsafe { let videoalignment = ffi::GstVideoAlignment {
let mut videoalignment: ffi::GstVideoAlignment = mem::zeroed(); padding_top,
padding_bottom,
videoalignment.padding_top = padding_top; padding_left,
videoalignment.padding_bottom = padding_bottom; padding_right,
videoalignment.padding_left = padding_left; stride_align: *stride_align,
videoalignment.padding_right = padding_right;
videoalignment.stride_align = *stride_align;
videoalignment
}; };
VideoAlignment(videoalignment) VideoAlignment(videoalignment)

View file

@ -84,15 +84,11 @@ impl VideoColorimetry {
) -> Self { ) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let colorimetry = unsafe { let colorimetry = ffi::GstVideoColorimetry {
let mut colorimetry: ffi::GstVideoColorimetry = mem::zeroed(); range: range.to_glib(),
matrix: matrix.to_glib(),
colorimetry.range = range.to_glib(); transfer: transfer.to_glib(),
colorimetry.matrix = matrix.to_glib(); primaries: primaries.to_glib(),
colorimetry.transfer = transfer.to_glib();
colorimetry.primaries = primaries.to_glib();
colorimetry
}; };
VideoColorimetry(colorimetry) VideoColorimetry(colorimetry)

View file

@ -32,14 +32,13 @@ impl AllocationParams {
pub fn new(flags: MemoryFlags, align: usize, prefix: usize, padding: usize) -> Self { pub fn new(flags: MemoryFlags, align: usize, prefix: usize, padding: usize) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let allocationparams = unsafe { let allocationparams = unsafe {
let mut allocationparams: ffi::GstAllocationParams = mem::zeroed(); ffi::GstAllocationParams {
flags: flags.to_glib(),
allocationparams.flags = flags.to_glib(); align,
allocationparams.align = align; prefix,
allocationparams.prefix = prefix; padding,
allocationparams.padding = padding; ..mem::zeroed()
}
allocationparams
}; };
AllocationParams(allocationparams) AllocationParams(allocationparams)