1 // Copyright 2023 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 use proc_macro2::Ident; 16 use quote::format_ident; 17 get_integer_type(width: usize) -> Ident18pub fn get_integer_type(width: usize) -> Ident { 19 let best_width = [8, 16, 32, 64] 20 .into_iter() 21 .filter(|x| *x >= width) 22 .min() 23 .unwrap_or_else(|| panic!("width {width} is too large")); 24 format_ident!("u{best_width}") 25 } 26 27 /// Generate a block of code. 28 /// 29 /// Like `quote!`, but the code block will be followed by an empty 30 /// line of code. This makes the generated code more readable. 31 #[macro_export] 32 macro_rules! quote_block { 33 ($($tt:tt)*) => { 34 format!("{}\n\n", ::quote::quote!($($tt)*)) 35 } 36 } 37