Skip to content

Commit 8943f02

Browse files
committed
capi: Shorten normalization reason code/tests a bit
Shorten the normalization reason code & tests a bit by glob importing the blaze_normalize_reason variants. Signed-off-by: Daniel Müller <[email protected]>
1 parent a126759 commit 8943f02

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

capi/src/normalize.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,12 @@ pub enum blaze_normalize_reason {
375375

376376
impl From<Reason> for blaze_normalize_reason {
377377
fn from(reason: Reason) -> Self {
378+
use blaze_normalize_reason::*;
379+
378380
match reason {
379-
Reason::Unmapped => blaze_normalize_reason::BLAZE_NORMALIZE_REASON_UNMAPPED,
380-
Reason::MissingComponent => {
381-
blaze_normalize_reason::BLAZE_NORMALIZE_REASON_MISSING_COMPONENT
382-
}
383-
Reason::Unsupported => blaze_normalize_reason::BLAZE_NORMALIZE_REASON_UNSUPPORTED,
381+
Reason::Unmapped => BLAZE_NORMALIZE_REASON_UNMAPPED,
382+
Reason::MissingComponent => BLAZE_NORMALIZE_REASON_MISSING_COMPONENT,
383+
Reason::Unsupported => BLAZE_NORMALIZE_REASON_UNSUPPORTED,
384384
_ => unreachable!(),
385385
}
386386
}
@@ -390,14 +390,16 @@ impl From<Reason> for blaze_normalize_reason {
390390
/// Retrieve a textual representation of the reason of a normalization failure.
391391
#[no_mangle]
392392
pub extern "C" fn blaze_normalize_reason_str(err: blaze_normalize_reason) -> *const c_char {
393+
use blaze_normalize_reason::*;
394+
393395
match err as i32 {
394-
e if e == blaze_normalize_reason::BLAZE_NORMALIZE_REASON_UNMAPPED as i32 => {
396+
e if e == BLAZE_NORMALIZE_REASON_UNMAPPED as i32 => {
395397
Reason::Unmapped.as_bytes().as_ptr().cast()
396398
}
397-
e if e == blaze_normalize_reason::BLAZE_NORMALIZE_REASON_MISSING_COMPONENT as i32 => {
399+
e if e == BLAZE_NORMALIZE_REASON_MISSING_COMPONENT as i32 => {
398400
Reason::MissingComponent.as_bytes().as_ptr().cast()
399401
}
400-
e if e == blaze_normalize_reason::BLAZE_NORMALIZE_REASON_UNSUPPORTED as i32 => {
402+
e if e == BLAZE_NORMALIZE_REASON_UNSUPPORTED as i32 => {
401403
Reason::Unsupported.as_bytes().as_ptr().cast()
402404
}
403405
_ => b"unknown reason\0".as_ptr().cast(),
@@ -805,19 +807,15 @@ mod tests {
805807
#[tag(miri)]
806808
#[test]
807809
fn reason_stringification() {
810+
use blaze_normalize_reason::*;
811+
808812
let data = [
809-
(
810-
Reason::Unmapped,
811-
blaze_normalize_reason::BLAZE_NORMALIZE_REASON_UNMAPPED,
812-
),
813+
(Reason::Unmapped, BLAZE_NORMALIZE_REASON_UNMAPPED),
813814
(
814815
Reason::MissingComponent,
815-
blaze_normalize_reason::BLAZE_NORMALIZE_REASON_MISSING_COMPONENT,
816-
),
817-
(
818-
Reason::Unsupported,
819-
blaze_normalize_reason::BLAZE_NORMALIZE_REASON_UNSUPPORTED,
816+
BLAZE_NORMALIZE_REASON_MISSING_COMPONENT,
820817
),
818+
(Reason::Unsupported, BLAZE_NORMALIZE_REASON_UNSUPPORTED),
821819
];
822820

823821
for (reason, expected) in data {

0 commit comments

Comments
 (0)