1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#![no_std]
//! A macro for creating c-style u16 wide strings at compile time.
//!
//! ## Example
//! ```rust
//! use u16cstr::{u16cstr, u16str};
//! use widestring::{U16CString, U16String, U16CStr, U16Str};
//!
//! // c-style terminated wide string
//! const wide_c_string: &U16CStr = u16cstr!("Test");
//! assert_eq!(wide_c_string, U16CString::from_str("Test").unwrap().as_ucstr());
//!
//! // non-terminated wide string
//! const wide_string: &U16Str = u16str!("Test");
//! assert_eq!(wide_string, U16String::from_str("Test").as_ustr());
//! ```
pub extern crate wchar;
pub extern crate widestring;
/// A macro for creating c-style u16 wide strings at compile time.
///
/// ## Example
/// ```rust
/// use u16cstr::u16cstr;
/// use widestring::{U16CString, U16CStr};
///
/// const wide_c_string: &U16CStr = u16cstr!("Test");
/// assert_eq!(wide_c_string, U16CString::from_str("Test").unwrap().as_ucstr());
/// ```
#[macro_export]
macro_rules! u16cstr {
($expression:expr) => {{
// the following would be nice to use but it is sadly not const.
// unsafe { $crate::widestring::U16CStr::from_slice_unchecked($crate::wchar::wchz!(u16, $expression)) }
unsafe { ::core::mem::transmute::<&'static [u16], &'static $crate::widestring::U16CStr>($crate::wchar::wchz!(u16, $expression)) }
}};
}
/// A macro for creating u16 wide strings at compile time.
///
/// ## Example
/// ```rust
/// use u16cstr::{u16cstr, u16str};
/// use widestring::{U16String, U16Str};
///
/// const wide_string: &U16Str = u16str!("Test");
/// assert_eq!(wide_string, U16String::from_str("Test").as_ustr());
/// ```
#[macro_export]
macro_rules! u16str {
($expression:expr) => {{
// the following would be nice to use but it is sadly not const.
// unsafe { $crate::widestring::U16Str::from_slice($crate::wchar::wch!(u16, $expression)) }
unsafe {
::core::mem::transmute::<&'static [u16], &'static $crate::widestring::U16Str>(
$crate::wchar::wch!(u16, $expression),
)
}
}};
}