Skip to content

Commit efe601a

Browse files
committed
simplyfy enum defaults
using `#[default]` marker from rustc 1.62 with which the implementation can be simply derived.
1 parent 664df4d commit efe601a

File tree

3 files changed

+6
-24
lines changed

3 files changed

+6
-24
lines changed

pulse-binding/src/channelmap.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ pub const POSITION_MASK_ALL: PositionMask = 0xffffffffffffffffu64;
5252
/// Note, certain aliases, specifically `Left`, `Right`, `Center` and `Subwoofer`, available in the
5353
/// equivalent C enum are not provided here, since Rust does not allow aliases.
5454
#[repr(C)]
55-
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
55+
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
5656
#[derive(FromPrimitive, ToPrimitive)]
5757
pub enum Position {
5858
/* NOTE: This enum’s variants and variant values **must** remain identical to the `sys` crate
5959
(C API) equivalent */
6060

6161
/// Invalid.
62+
#[default]
6263
Invalid = -1,
6364

6465
/// Mono.
@@ -180,13 +181,6 @@ pub enum Position {
180181
TopRearCenter,
181182
}
182183

183-
impl Default for Position {
184-
#[inline(always)]
185-
fn default() -> Self {
186-
Position::Invalid
187-
}
188-
}
189-
190184
/// Check is equal to `sys` equivalent
191185
#[test]
192186
fn pos_compare_capi() {

pulse-binding/src/format.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub use capi::pa_prop_type_t as PropType;
3232
/// Represents the type of encoding used in a stream or accepted by a sink.
3333
#[repr(C)]
3434
#[non_exhaustive]
35-
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
35+
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
3636
#[derive(FromPrimitive, ToPrimitive)]
3737
#[allow(non_camel_case_types)]
3838
pub enum Encoding {
@@ -62,6 +62,7 @@ pub enum Encoding {
6262
DTSHD_IEC61937,
6363

6464
/// Represents an invalid encoding.
65+
#[default]
6566
Invalid = -1,
6667
}
6768

@@ -100,13 +101,6 @@ impl From<capi::pa_encoding_t> for Encoding {
100101
}
101102
}
102103

103-
impl Default for Encoding {
104-
#[inline(always)]
105-
fn default() -> Self {
106-
Encoding::Invalid
107-
}
108-
}
109-
110104
/// Represents the format of data provided in a stream or processed by a sink.
111105
pub struct Info {
112106
/// The actual C object.

pulse-binding/src/sample.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ use crate::time::MicroSeconds;
7474
/// should be preferred over direct use of the endian-specific variants, for improved flexibility
7575
/// and avoidance of mistakes.
7676
#[repr(C)]
77-
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
77+
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
7878
#[derive(FromPrimitive, ToPrimitive)]
7979
#[allow(non_camel_case_types)]
8080
pub enum Format {
@@ -108,6 +108,7 @@ pub enum Format {
108108
S24_32be,
109109

110110
/// An invalid value.
111+
#[default]
111112
Invalid = -1,
112113
}
113114

@@ -148,13 +149,6 @@ impl From<capi::pa_sample_format_t> for Format {
148149
}
149150
}
150151

151-
impl Default for Format {
152-
#[inline(always)]
153-
fn default() -> Self {
154-
Format::Invalid
155-
}
156-
}
157-
158152
/// Endian-independent format identifiers, for big-endian systems.
159153
#[cfg(target_endian = "big")]
160154
mod ei_formats {

0 commit comments

Comments
 (0)