I have the following C++ structure that I want to rewrite in Rust:
struct Fraction
{
int numerator;
int denominator;
};
struct PixelFormat
{
Fraction yuvSizes[3];
Fraction yuvWidths[3];
Fraction yuvHeights[3];
int yuvInternalFormat[3];
int yuvGlFormat[3];
int textureFormat;
bool isPlanar;
int dataType;
std::string humanReadablePixelFormat;
};
I need to access this map fast. It cannot be an array, unfortunately.
I initiate them in C++ statically like this:
static std::map<int, PixelFormat> pixelFormats;
pixelFormats[AV_PIX_FMT_YUV420P] = PixelFormat {
//Fraction yuvSizes[3];
{one,one,one},
//Fraction yuvWidths[3];
{one,two,two},
//Fraction yuvHeights[3];
{one,two,two},
//GLint yuvInternalFormat[3];
{GL_SYMBOLS::GL__RED,GL_SYMBOLS::GL__RED,GL_SYMBOLS::GL__RED},
//GLenum yuvGlFormat[3];
{GL_SYMBOLS::GL__RED,GL_SYMBOLS::GL__RED,GL_SYMBOLS::GL__RED},
//int textureFormat
YUV,
//bool isPlanar
true,
//GLenum dataType
GL_SYMBOLS::GL__UNSIGNED_BYTE,
//std::string humanReadablePixelFormat
"AV_PIX_FMT_YUV420P"
};
This is generated by a python script. It's a table of color conversions for video. Everything is constant.
On Rust there is no static so I'm confused on a good way of doing this map. Ideally I'd like something like this:
const pixel_formats: Map<PixelFormat> = {
AV_PIX_FMT_YUV420P => Fraction{
//...
}
//...
}
Maybe a map is too much and there's something lighter on Rust?