Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

50.5.1Generic enum

To accept a different type for grey, we use two parameters G and C:

We can then test this enum on a grey level and an RGB color:

(Grey(41140), Rgb(96, 112, 128))

50.5.2Generic function for getting env vars

Server starting on localhost:8080

50.5.3Integer wrapper

We use the PrimInt trait from the num-traits crate to restrict T to primitive integer types. PrimInt does not provide an is_power_of_two() method directly, so we implement it using count_ones(), which is available on PrimInt: a strictly positive integer is a power of two when it has exactly one bit set. This example requires the external num_traits crate, which is not available in this notebook’s kernel, so it is shown but not executed: