Skip to content

Commit 47a8e64

Browse files
committed
spa-sys: Don't prefix enum name to enum variant bindings
The enum variants are already named with prefixes, so this seems fairly redundant.
1 parent 314ad46 commit 47a8e64

File tree

5 files changed

+43
-54
lines changed

5 files changed

+43
-54
lines changed

libspa-sys/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fn main() {
2424
.allowlist_type("spa_.*")
2525
.allowlist_var("spa_.*")
2626
.allowlist_var("SPA_.*")
27+
.prepend_enum_name(false)
2728
.derive_eq(true);
2829

2930
let builder = libs

libspa/src/direction.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ impl Direction {
1616
/// The raw representation of the direction
1717
pub fn as_raw(&self) -> spa_sys::spa_direction {
1818
match self {
19-
Self::Input => spa_sys::spa_direction_SPA_DIRECTION_INPUT,
20-
Self::Output => spa_sys::spa_direction_SPA_DIRECTION_OUTPUT,
19+
Self::Input => spa_sys::SPA_DIRECTION_INPUT,
20+
Self::Output => spa_sys::SPA_DIRECTION_OUTPUT,
2121
}
2222
}
2323

@@ -27,8 +27,8 @@ impl Direction {
2727
/// This function will panic if `raw` is an invalid direction.
2828
pub fn from_raw(raw: spa_sys::spa_direction) -> Self {
2929
match raw {
30-
spa_sys::spa_direction_SPA_DIRECTION_INPUT => Self::Input,
31-
spa_sys::spa_direction_SPA_DIRECTION_OUTPUT => Self::Output,
30+
spa_sys::SPA_DIRECTION_INPUT => Self::Input,
31+
spa_sys::SPA_DIRECTION_OUTPUT => Self::Output,
3232
_ => panic!("Invalid direction: {}", raw),
3333
}
3434
}
@@ -48,25 +48,19 @@ mod tests {
4848

4949
#[test]
5050
fn as_raw() {
51-
assert_eq!(
52-
Direction::Input.as_raw(),
53-
spa_sys::spa_direction_SPA_DIRECTION_INPUT
54-
);
55-
assert_eq!(
56-
Direction::Output.as_raw(),
57-
spa_sys::spa_direction_SPA_DIRECTION_OUTPUT
58-
);
51+
assert_eq!(Direction::Input.as_raw(), spa_sys::SPA_DIRECTION_INPUT);
52+
assert_eq!(Direction::Output.as_raw(), spa_sys::SPA_DIRECTION_OUTPUT);
5953
}
6054

6155
#[test]
6256
fn from_raw() {
6357
assert_eq!(
6458
Direction::Input,
65-
Direction::from_raw(spa_sys::spa_direction_SPA_DIRECTION_INPUT)
59+
Direction::from_raw(spa_sys::SPA_DIRECTION_INPUT)
6660
);
6761
assert_eq!(
6862
Direction::Output,
69-
Direction::from_raw(spa_sys::spa_direction_SPA_DIRECTION_OUTPUT)
63+
Direction::from_raw(spa_sys::SPA_DIRECTION_OUTPUT)
7064
);
7165
}
7266

libspa/src/pod/deserialize.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -643,14 +643,14 @@ impl<'de, 'a> PodDeserializer<'de> {
643643
let flags = ChoiceFlags::from_bits(flags).expect("invalid choice flags");
644644

645645
match choice_type {
646-
spa_sys::spa_choice_type_SPA_CHOICE_None => {
646+
spa_sys::SPA_CHOICE_None => {
647647
if values.is_empty() {
648648
Err(DeserializeError::MissingChoiceValues)
649649
} else {
650650
Ok(Choice(ChoiceFlags::empty(), ChoiceEnum::None(values[0])))
651651
}
652652
}
653-
spa_sys::spa_choice_type_SPA_CHOICE_Range => {
653+
spa_sys::SPA_CHOICE_Range => {
654654
if values.len() < 3 {
655655
Err(DeserializeError::MissingChoiceValues)
656656
} else {
@@ -664,7 +664,7 @@ impl<'de, 'a> PodDeserializer<'de> {
664664
))
665665
}
666666
}
667-
spa_sys::spa_choice_type_SPA_CHOICE_Step => {
667+
spa_sys::SPA_CHOICE_Step => {
668668
if values.len() < 4 {
669669
Err(DeserializeError::MissingChoiceValues)
670670
} else {
@@ -679,7 +679,7 @@ impl<'de, 'a> PodDeserializer<'de> {
679679
))
680680
}
681681
}
682-
spa_sys::spa_choice_type_SPA_CHOICE_Enum => {
682+
spa_sys::SPA_CHOICE_Enum => {
683683
if values.is_empty() {
684684
Err(DeserializeError::MissingChoiceValues)
685685
} else {
@@ -692,7 +692,7 @@ impl<'de, 'a> PodDeserializer<'de> {
692692
))
693693
}
694694
}
695-
spa_sys::spa_choice_type_SPA_CHOICE_Flags => {
695+
spa_sys::SPA_CHOICE_Flags => {
696696
if values.is_empty() {
697697
Err(DeserializeError::MissingChoiceValues)
698698
} else {

libspa/src/pod/serialize.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -435,32 +435,28 @@ impl<O: Write + Seek> PodSerializer<O> {
435435
let flags = choice.0;
436436

437437
let (choice_type, values) = match &choice.1 {
438-
ChoiceEnum::None(value) => (spa_sys::spa_choice_type_SPA_CHOICE_None, vec![value]),
439-
ChoiceEnum::Range { default, min, max } => (
440-
spa_sys::spa_choice_type_SPA_CHOICE_Range,
441-
vec![default, min, max],
442-
),
438+
ChoiceEnum::None(value) => (spa_sys::SPA_CHOICE_None, vec![value]),
439+
ChoiceEnum::Range { default, min, max } => {
440+
(spa_sys::SPA_CHOICE_Range, vec![default, min, max])
441+
}
443442
ChoiceEnum::Step {
444443
default,
445444
min,
446445
max,
447446
step,
448-
} => (
449-
spa_sys::spa_choice_type_SPA_CHOICE_Step,
450-
vec![default, min, max, step],
451-
),
447+
} => (spa_sys::SPA_CHOICE_Step, vec![default, min, max, step]),
452448
ChoiceEnum::Enum {
453449
default,
454450
alternatives,
455451
} => {
456452
let mut values = vec![default];
457453
values.extend(alternatives);
458-
(spa_sys::spa_choice_type_SPA_CHOICE_Enum, values)
454+
(spa_sys::SPA_CHOICE_Enum, values)
459455
}
460456
ChoiceEnum::Flags { default, flags } => {
461457
let mut values = vec![default];
462458
values.extend(flags);
463-
(spa_sys::spa_choice_type_SPA_CHOICE_Flags, values)
459+
(spa_sys::SPA_CHOICE_Flags, values)
464460
}
465461
};
466462

libspa/tests/pod.rs

+22-24
Original file line numberDiff line numberDiff line change
@@ -1371,10 +1371,10 @@ fn object() {
13711371
object_deserializer: &mut ObjectPodDeserializer<'de>,
13721372
) -> Result<Self::Value, DeserializeError<&'de [u8]>> {
13731373
let (device, _flags) = object_deserializer
1374-
.deserialize_property_key::<String>(spa_sys::spa_prop_SPA_PROP_device)?;
1374+
.deserialize_property_key::<String>(spa_sys::SPA_PROP_device)?;
13751375

13761376
let (frequency, _flags) = object_deserializer
1377-
.deserialize_property_key::<f32>(spa_sys::spa_prop_SPA_PROP_frequency)?;
1377+
.deserialize_property_key::<f32>(spa_sys::SPA_PROP_frequency)?;
13781378

13791379
Ok(MyProps { device, frequency })
13801380
}
@@ -1401,15 +1401,15 @@ fn object() {
14011401
&[] as &[u8],
14021402
Value::Object(Object {
14031403
type_: spa_sys::SPA_TYPE_OBJECT_Props,
1404-
id: spa_sys::spa_param_type_SPA_PARAM_Props,
1404+
id: spa_sys::SPA_PARAM_Props,
14051405
properties: vec![
14061406
Property {
1407-
key: spa_sys::spa_prop_SPA_PROP_device,
1407+
key: spa_sys::SPA_PROP_device,
14081408
flags: PropertyFlags::empty(),
14091409
value: Value::String("hw:0".into()),
14101410
},
14111411
Property {
1412-
key: spa_sys::spa_prop_SPA_PROP_frequency,
1412+
key: spa_sys::SPA_PROP_frequency,
14131413
flags: PropertyFlags::empty(),
14141414
value: Value::Float(440.0)
14151415
}
@@ -1424,18 +1424,16 @@ fn object() {
14241424
&self,
14251425
serializer: PodSerializer<O>,
14261426
) -> Result<SerializeSuccess<O>, cookie_factory::GenError> {
1427-
let mut obj_serializer = serializer.serialize_object(
1428-
spa_sys::SPA_TYPE_OBJECT_Props,
1429-
spa_sys::spa_param_type_SPA_PARAM_Props,
1430-
)?;
1427+
let mut obj_serializer = serializer
1428+
.serialize_object(spa_sys::SPA_TYPE_OBJECT_Props, spa_sys::SPA_PARAM_Props)?;
14311429

14321430
obj_serializer.serialize_property(
1433-
spa_sys::spa_prop_SPA_PROP_device,
1431+
spa_sys::SPA_PROP_device,
14341432
"hw:0",
14351433
PropertyFlags::empty(),
14361434
)?;
14371435
obj_serializer.serialize_property(
1438-
spa_sys::spa_prop_SPA_PROP_frequency,
1436+
spa_sys::SPA_PROP_frequency,
14391437
&440.0_f32,
14401438
PropertyFlags::empty(),
14411439
)?;
@@ -1482,7 +1480,7 @@ fn choice_range_f32() {
14821480
c::build_choice_f32(
14831481
vec_c.as_mut_ptr(),
14841482
vec_c.len(),
1485-
spa_sys::spa_choice_type_SPA_CHOICE_Range,
1483+
spa_sys::SPA_CHOICE_Range,
14861484
0,
14871485
3,
14881486
&[440.0_f32, 110.0, 880.0] as *const f32,
@@ -1534,7 +1532,7 @@ fn choice_range_i32() {
15341532
c::build_choice_i32(
15351533
vec_c.as_mut_ptr(),
15361534
vec_c.len(),
1537-
spa_sys::spa_choice_type_SPA_CHOICE_Range,
1535+
spa_sys::SPA_CHOICE_Range,
15381536
0,
15391537
3,
15401538
&[5, 2, 10] as *const i32,
@@ -1579,7 +1577,7 @@ fn choice_none_i32() {
15791577
c::build_choice_i32(
15801578
vec_c.as_mut_ptr(),
15811579
vec_c.len(),
1582-
spa_sys::spa_choice_type_SPA_CHOICE_None,
1580+
spa_sys::SPA_CHOICE_None,
15831581
0,
15841582
1,
15851583
&[5] as *const i32,
@@ -1632,7 +1630,7 @@ fn choice_step_i32() {
16321630
c::build_choice_i32(
16331631
vec_c.as_mut_ptr(),
16341632
vec_c.len(),
1635-
spa_sys::spa_choice_type_SPA_CHOICE_Step,
1633+
spa_sys::SPA_CHOICE_Step,
16361634
0,
16371635
4,
16381636
&[5, 2, 10, 1] as *const i32,
@@ -1683,7 +1681,7 @@ fn choice_enum_i32() {
16831681
c::build_choice_i32(
16841682
vec_c.as_mut_ptr(),
16851683
vec_c.len(),
1686-
spa_sys::spa_choice_type_SPA_CHOICE_Enum,
1684+
spa_sys::SPA_CHOICE_Enum,
16871685
0,
16881686
4,
16891687
&[5, 2, 10, 1] as *const i32,
@@ -1734,7 +1732,7 @@ fn choice_flags_i32() {
17341732
c::build_choice_i32(
17351733
vec_c.as_mut_ptr(),
17361734
vec_c.len(),
1737-
spa_sys::spa_choice_type_SPA_CHOICE_Flags,
1735+
spa_sys::SPA_CHOICE_Flags,
17381736
0,
17391737
4,
17401738
&[5, 2, 10, 1] as *const i32,
@@ -1786,7 +1784,7 @@ fn choice_range_i64() {
17861784
c::build_choice_i64(
17871785
vec_c.as_mut_ptr(),
17881786
vec_c.len(),
1789-
spa_sys::spa_choice_type_SPA_CHOICE_Range,
1787+
spa_sys::SPA_CHOICE_Range,
17901788
0,
17911789
3,
17921790
&[440_i64, 110, 880] as *const i64,
@@ -1838,7 +1836,7 @@ fn choice_range_f64() {
18381836
c::build_choice_f64(
18391837
vec_c.as_mut_ptr(),
18401838
vec_c.len(),
1841-
spa_sys::spa_choice_type_SPA_CHOICE_Range,
1839+
spa_sys::SPA_CHOICE_Range,
18421840
0,
18431841
3,
18441842
&[440.0_f64, 110.0, 880.0] as *const f64,
@@ -1889,7 +1887,7 @@ fn choice_enum_id() {
18891887
c::build_choice_id(
18901888
vec_c.as_mut_ptr(),
18911889
vec_c.len(),
1892-
spa_sys::spa_choice_type_SPA_CHOICE_Enum,
1890+
spa_sys::SPA_CHOICE_Enum,
18931891
0,
18941892
4,
18951893
&[5_u32, 2, 10, 1] as *const u32,
@@ -1952,7 +1950,7 @@ fn choice_enum_rectangle() {
19521950
c::build_choice_rectangle(
19531951
vec_c.as_mut_ptr(),
19541952
vec_c.len(),
1955-
spa_sys::spa_choice_type_SPA_CHOICE_Enum,
1953+
spa_sys::SPA_CHOICE_Enum,
19561954
0,
19571955
6,
19581956
&[800_u32, 600, 1920, 1080, 300, 200] as *const u32,
@@ -2003,7 +2001,7 @@ fn choice_enum_fraction() {
20032001
c::build_choice_fraction(
20042002
vec_c.as_mut_ptr(),
20052003
vec_c.len(),
2006-
spa_sys::spa_choice_type_SPA_CHOICE_Enum,
2004+
spa_sys::SPA_CHOICE_Enum,
20072005
0,
20082006
6,
20092007
&[1_u32, 2, 2, 3, 1, 3] as *const u32,
@@ -2054,7 +2052,7 @@ fn choice_enum_fd() {
20542052
c::build_choice_fd(
20552053
vec_c.as_mut_ptr(),
20562054
vec_c.len(),
2057-
spa_sys::spa_choice_type_SPA_CHOICE_Enum,
2055+
spa_sys::SPA_CHOICE_Enum,
20582056
0,
20592057
4,
20602058
&[5_i64, 2, 10, 1] as *const i64,
@@ -2088,7 +2086,7 @@ fn choice_extra_values() {
20882086
c::build_choice_i32(
20892087
vec_c.as_mut_ptr(),
20902088
vec_c.len(),
2091-
spa_sys::spa_choice_type_SPA_CHOICE_None,
2089+
spa_sys::SPA_CHOICE_None,
20922090
0,
20932091
1,
20942092
&[5, 6, 7, 8] as *const i32,

0 commit comments

Comments
 (0)