@@ -9,7 +9,7 @@ use quote::{quote, quote_spanned, TokenStreamExt};
99use syn:: spanned:: Spanned ;
1010use 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
1515macro_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