Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/pulse/src/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 1 kB image not shown  

Quelle  error.rs   Sprache: unbekannt

 
// Copyright © 2017 Mozilla Foundation
//
// This program is made available under an ISC-style license.  See the
// accompanying file LICENSE for details.

use ffi;
use std::ffi::CStr;

#[macro_export]
macro_rules! error_result {
    ($t:expr, $err:expr) => {
        if $err >= 0 {
            Ok($t)
        } else {
            Err(ErrorCode::from_error_result($err))
        }
    };
}

#[derive(Debug, PartialEq)]
pub struct ErrorCode {
    err: ffi::pa_error_code_t,
}

impl ErrorCode {
    pub fn from_error_result(err: i32) -> Self {
        debug_assert!(err < 0);
        ErrorCode {
            err: (-err) as ffi::pa_error_code_t,
        }
    }

    pub fn from_error_code(err: ffi::pa_error_code_t) -> Self {
        debug_assert!(err > 0);
        ErrorCode { err: err }
    }

    fn desc(&self) -> &'static str {
        let cstr = unsafe { CStr::from_ptr(ffi::pa_strerror(self.err)) };
        cstr.to_str().unwrap()
    }
}

impl ::std::error::Error for ErrorCode {
    fn description(&self) -> &str {
        self.desc()
    }
}

impl ::std::fmt::Display for ErrorCode {
    fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
        write!(f, "{:?}: {}", self, self.desc())
    }
}

[ Dauer der Verarbeitung: 0.2 Sekunden  (vorverarbeitet)  ]