To learn Mozilla Rust, I try to convert an existing .NET / C# application to Rust.
So far, I have created an enumeration which represents different PDF versions.
#[derive(PartialEq, Debug)]
pub enum PDFVersion {
V14,
V15,
V16,
V17,
V20,
V21,
}
And I also created a struct which represents a PDF Writer, which accepts a PDFVersion
instance.
pub struct PDFWriter {
version: PDFVersion,
}
// Provides the 'basic' implementation of the `PDFVersion` struct.
impl PDFWriter {
pub fn new(version: PDFVersion) -> Self {
PDFWriter { version }
}
}
Now, I did want to create a couple of tests to ensure that PDFWriter::new
results in a PDFWriter
instance with the passed PDFVersion
, so here are the tests:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new_pdfwriter() {
[
PDFVersion::V14,
PDFVersion::V15,
PDFVersion::V16,
PDFVersion::V17,
PDFVersion::V20,
PDFVersion::V21,
]
.iter()
.for_each(|version| {
// ACT.
let result = PDFWriter::new(*version);
// ASSERT.
assert_eq!(result.version, *version);
});
}
}
At the moment, this test does NOT work since I need to dereference the pointer to version, but in order to do that, the PDFVersion
enumeration should also derive from Copy
and Clone
.
I'm not sure if that's the good approach. I always wonder if adding those traits might impact the performance of the code.
Should I be concerned and "On Guard" when implementing this traits regarding performance?