MCPcopy Create free account
hub / github.com/Lymia/enumset / enum_repr

Method enum_repr

enumset_derive/src/plan.rs:307–333  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

305 }
306
307 pub fn enum_repr(&self) -> Ident {
308 if let Some(ident) = &self.explicit_enum_repr {
309 ident.clone()
310 } else {
311 if self.min_discriminant >= 0 {
312 match self.max_discriminant {
313 x if x <= u8::MAX as i64 => Ident::new("u8", Span::call_site()),
314 x if x <= u16::MAX as i64 => Ident::new("u16", Span::call_site()),
315 x if x <= u32::MAX as i64 => Ident::new("u32", Span::call_site()),
316 _ => Ident::new("u64", Span::call_site()),
317 }
318 } else {
319 match (self.max_discriminant, self.min_discriminant) {
320 (max, min) if max <= i8::MAX as i64 && min >= i8::MIN as i64 => {
321 Ident::new("i8", Span::call_site())
322 }
323 (max, min) if max <= i16::MAX as i64 && min >= i16::MIN as i64 => {
324 Ident::new("i16", Span::call_site())
325 }
326 (max, min) if max <= i32::MAX as i64 && min >= i32::MIN as i64 => {
327 Ident::new("i32", Span::call_site())
328 }
329 _ => Ident::new("i64", Span::call_site()),
330 }
331 }
332 }
333 }
334
335 /// Returns the number of bits this enumset takes.
336 pub fn bit_width(&self) -> u32 {

Callers 2

generate_codeFunction · 0.80
create_enum_conversionsFunction · 0.80

Calls 1

newFunction · 0.85

Tested by

no test coverage detected