Browse Source

Implement `Display` trait for Error enum

fixes
Andreas Linz 5 years ago
parent
commit
5f71b52ae0
1 changed files with 7 additions and 0 deletions
  1. +7
    -0
      src/ffi.rs

+ 7
- 0
src/ffi.rs View File

@ -4,6 +4,7 @@ use std::os::raw::{c_char, c_int};
use std::str::Utf8Error;
use std::ffi::CStr;
use std::ffi::CString;
use std::fmt::Display;
fn ptr_to_string(str_ptr: *const c_char) -> Result<String, Utf8Error> {
let str_slice: &str = try!(unsafe { CStr::from_ptr(str_ptr) }.to_str());
@ -30,6 +31,12 @@ pub enum Enum_SoundIoError {
SoundIoErrorUnderflow = 14,
SoundIoErrorEncodingString = 15,
}
impl Display for Enum_SoundIoError {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
let str_ptr = unsafe { soundio_strerror(*self) };
write!(f, "{}", ptr_to_string(str_ptr).unwrap())
}
}
#[derive(Clone, Copy)]
#[repr(u32)]

Loading…
Cancel
Save