I'm writing a prime number checker that works on types with trait FromPrimitive (which is part of my Numeric trait):
fn is_prime<T: Numeric>(n: T) -> bool
There are a few tests to check this but the first is a simple check to see if it's divisible by any prime less than 1000 to which end, I've got a static array of i32 which contains all 168 such primes. The easiest way to do this is just to pull these i32s out and run T::from_i32(p) on each of them, but can be a rather involved conversion and this prime checker can potentially be called LOTS so I want this to be more efficient. In particular, ideally I'd like to have is_prime create an array of T type primes if it hasn't already been created and pull it's values from that so that this conversion is only done once and not every time you call is_prime(). At first I thought I'd create a TypeMap variable as a lazy_static and then use that to reference for T, creating a new entry if one didn't exist. The problem is that it has to be mutable so I can add the array later and lazy_static doesn't like mutable things. So the question is:
How best to go about doing such a thing?