I'm looking for a generic mechanism that will allow me to get double precision version of given integer type
u8 -> u16
u16 -> u32
and so on.
In C++ we can define template structure
#include <cstddef>
using undefined = void;
template <class T>
struct double_precision {
using type = undefined;
};
template <class T>
using double_precision_t = typename double_precision<T>::type;
and add specializations
template <>
struct double_precision<std::uint8_t> {
using type = std::uint16_t;
};
template <>
struct double_precision<std::uint16_t> {
using type = std::uint32_t;
};
template <>
struct double_precision<std::uint32_t> {
using type = std::uint64_t;
};
and after that get double precision version with double_precision_t<T> like in
template<class T>
double_precision_t<T> square(T value) {
double_precision_t<T> double_precision_value = value;
return double_precision_value * double_precision_value;
}
How can we do similar thing in Rust?