Skip to content

Commit 371f7b7

Browse files
uefi-macros: Drop the cstr8 macro
This is replaced by a new `cstr8` declarative macro in the `uefi` crate.
1 parent bdb290c commit 371f7b7

File tree

2 files changed

+3
-44
lines changed

2 files changed

+3
-44
lines changed

uefi-macros/CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# uefi-macros - [Unreleased]
22

33
## Removed
4-
- Removed the `cstr16` macro. Use the `cstr16` declarative macro exported by the
5-
`uefi` crate instead.
4+
- Removed the `cstr8` and `cstr16` macros. Use the declarative macros of the
5+
same names exported by the `uefi` crate as a replacement.
66

77
# uefi-macros - 0.13.0 (2023-11-12)
88

uefi-macros/src/lib.rs

+1-42
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use quote::{quote, quote_spanned, TokenStreamExt};
99
use syn::spanned::Spanned;
1010
use syn::{
1111
parse_macro_input, parse_quote, Error, Expr, ExprLit, ExprPath, FnArg, Ident, ItemFn,
12-
ItemStruct, Lit, LitStr, Pat, Visibility,
12+
ItemStruct, Lit, Pat, Visibility,
1313
};
1414

1515
macro_rules! err {
@@ -247,44 +247,3 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
247247
};
248248
result.into()
249249
}
250-
251-
/// Builds a `CStr8` literal at compile time from a string literal.
252-
///
253-
/// This will throw a compile error if an invalid character is in the passed string.
254-
///
255-
/// # Example
256-
/// ```
257-
/// # use uefi_macros::cstr8;
258-
/// // Empty string
259-
/// assert_eq!(cstr8!().to_u16_slice_with_nul(), [0]);
260-
/// assert_eq!(cstr8!("").to_u16_slice_with_nul(), [0]);
261-
/// // Non-empty string
262-
/// assert_eq!(cstr8!("test").as_bytes(), [116, 101, 115, 116, 0]);
263-
/// ```
264-
#[proc_macro]
265-
pub fn cstr8(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
266-
// Accept empty input.
267-
if input.is_empty() {
268-
return quote!(unsafe { ::uefi::CStr16::from_u16_with_nul_unchecked(&[0]) }).into();
269-
}
270-
let input: LitStr = parse_macro_input!(input);
271-
let input = input.value();
272-
// Accept "" input.
273-
if input.is_empty() {
274-
return quote!(unsafe { ::uefi::CStr16::from_u16_with_nul_unchecked(&[0]) }).into();
275-
}
276-
277-
// Accept any non-empty string input.
278-
match input
279-
.chars()
280-
.map(u8::try_from)
281-
.collect::<Result<Vec<u8>, _>>()
282-
{
283-
Ok(c) => {
284-
quote!(unsafe { ::uefi::CStr8::from_bytes_with_nul_unchecked(&[ #(#c),* , 0 ]) }).into()
285-
}
286-
Err(_) => syn::Error::new_spanned(input, "invalid character in string")
287-
.into_compile_error()
288-
.into(),
289-
}
290-
}

0 commit comments

Comments
 (0)