Skip to content

Commit ff7cc7a

Browse files
uefi-macros: Drop the cstr16 macro
This is replaced by a new `cstr16` declarative macro in the `uefi` crate.
1 parent a5a3ec1 commit ff7cc7a

File tree

2 files changed

+4
-44
lines changed

2 files changed

+4
-44
lines changed

uefi-macros/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# uefi-macros - [Unreleased]
22

3+
## Removed
4+
- Removed the `cstr16` macro. Use the `cstr16` declarative macro exported by the
5+
`uefi` crate instead.
6+
37
# uefi-macros - 0.13.0 (2023-11-12)
48

59
## Changed

uefi-macros/src/lib.rs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -288,47 +288,3 @@ pub fn cstr8(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
288288
.into(),
289289
}
290290
}
291-
292-
/// Builds a `CStr16` literal at compile time from a string literal.
293-
///
294-
/// This will throw a compile error if an invalid character is in the passed string.
295-
///
296-
/// # Example
297-
/// ```rust
298-
/// # use uefi_macros::cstr16;
299-
/// // Empty string
300-
/// assert_eq!(cstr16!().to_u16_slice_with_nul(), [0]);
301-
/// assert_eq!(cstr16!("").to_u16_slice_with_nul(), [0]);
302-
/// // Non-empty string
303-
/// assert_eq!(cstr16!("test €").to_u16_slice_with_nul(), [116, 101, 115, 116, 32, 8364, 0]);
304-
/// ```
305-
#[proc_macro]
306-
pub fn cstr16(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
307-
// Accept empty input.
308-
if input.is_empty() {
309-
return quote!(unsafe { ::uefi::CStr16::from_u16_with_nul_unchecked(&[0]) }).into();
310-
}
311-
let input: LitStr = parse_macro_input!(input);
312-
let input = input.value();
313-
// Accept "" input.
314-
if input.is_empty() {
315-
return quote!(unsafe { ::uefi::CStr16::from_u16_with_nul_unchecked(&[0]) }).into();
316-
}
317-
318-
// Accept any non-empty string input.
319-
match input
320-
.chars()
321-
.map(|c| u16::try_from(c as u32))
322-
.collect::<Result<Vec<u16>, _>>()
323-
{
324-
Ok(c) => {
325-
quote!(unsafe { ::uefi::CStr16::from_u16_with_nul_unchecked(&[ #(#c),* , 0 ]) }).into()
326-
}
327-
Err(_) => syn::Error::new_spanned(
328-
input,
329-
"There are UTF-8 characters that can't be transformed to UCS-2 character",
330-
)
331-
.into_compile_error()
332-
.into(),
333-
}
334-
}

0 commit comments

Comments
 (0)