ic4 0.0.2

A Rust bindings for IC Imaging Control 4 SDK from The Imaging Source. (Safe Part)
use std::{
    ffi::{CStr, CString},
    fmt::Display,
};

pub trait ToCStr {
    fn to_cstr(&self) -> &CStr;
}

pub trait ToCString {
    fn to_cstring(&self) -> CString;
}

impl ToCStr for CStr {
    fn to_cstr(&self) -> &CStr {
        self
    }
}

impl ToCStr for &CStr {
    fn to_cstr(&self) -> &CStr {
        self
    }
}

impl ToCStr for CString {
    fn to_cstr(&self) -> &CStr {
        self.as_c_str()
    }
}

/*
 * CStr: Display
 */

impl Display for dyn ToCStr {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.to_cstr().to_string_lossy().as_ref())
    }
}

impl Display for dyn ToCString {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.to_cstring().to_string_lossy().as_ref())
    }
}

/*
 * DefaultExt
 */

/// Same as std::prelude::Default.
pub trait DefaultExt {
    fn default_ext() -> Self;
}