Validate the enumset type.
(&self)
| 339 | |
| 340 | /// Validate the enumset type. |
| 341 | fn validate(&self) -> syn::Result<()> { |
| 342 | // Gets the span of the maximum value. |
| 343 | let largest_discriminant_span = match &self.max_variant_span { |
| 344 | Some(x) => *x, |
| 345 | None => Span::call_site(), |
| 346 | }; |
| 347 | |
| 348 | // Check if all bits of the bitset can fit in the memory representation, if one was given. |
| 349 | if self.internal_repr().supported_variants() <= self.max_variant_bit as usize { |
| 350 | error( |
| 351 | largest_discriminant_span, |
| 352 | "`repr` is too small to contain the largest discriminant.", |
| 353 | )?; |
| 354 | } |
| 355 | |
| 356 | // Check if all bits of the bitset can fit in the serialization representation. |
| 357 | if let Some(supported_variants) = self.serde_repr().supported_variants() { |
| 358 | if supported_variants <= self.max_variant_bit as usize { |
| 359 | error( |
| 360 | largest_discriminant_span, |
| 361 | "`serialize_repr` is too small to contain the largest discriminant.", |
| 362 | )?; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | // Checks if any bits of the variant are too large. |
| 367 | for variant in &self.variants { |
| 368 | if variant.variant_bit == !0 { |
| 369 | unreachable!("Sentinel value found in enumset plan!?"); |
| 370 | } |
| 371 | if variant.variant_bit >= 0xFFFFFFC0 { |
| 372 | error(variant.span, "Maximum variant bit allowed is `0xFFFFFFBF`.")?; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | Ok(()) |
| 377 | } |
| 378 | |
| 379 | /// Returns a bitmask of all variants in the set. |
| 380 | pub fn variant_map(&self) -> Vec<u64> { |
no test coverage detected