harbor run -t openthoughts/tasktrove-exp-rpt-stack-rust-v2-stack-rust-2686harbor download openthoughts/tasktrove-exp-rpt-stack-rust-v2-stack-rust-2686Task Description: Implement the Kennitala Struct Functionality
You need to implement the functionality for the Kennitala struct, which represents the unique national identification number (kennitala) of individuals in Iceland. The following requirements must be fulfilled to ensure that the provided tests pass:
Constructors:
Implement the new(kennitala: &str) method that validates and creates a Kennitala instance from a 10-character string.
Implement the from_u32(kennitala_u32: u32) method that creates a Kennitala instance from a 32-bit unsigned integer. This method should also include validation similar to the new method.
Validation Logic:
from_slice(kennitala: &[u8; 10]) method for constructing the Kennitala instance from an array by performing the necessary validations, including:
Accessors:
get_day(): Returns the day of birth.get_month(): Returns the month of birth.get_short_year(): Returns the last two digits of the year.get_year(): Returns the full year (1900 or 2000 + short year).get_short_century(): Returns the century digit (0 or 9).get_randoms(): Returns the combined value of the random digits and checksum digit.Display:
fmt::Display trait for the Kennitala struct to display it in the format "DDMMYYRRRC", where:
Checksum Calculation:
calculate_checksum_digit(kennitala: &[u8; 10]) function to compute the checksum digit based on the provided validation digits.Error Handling:
KennitalaError that captures potential validation failures, including invalid format, invalid length, invalid checksum, invalid random digits, invalid century, invalid month, and invalid day.Ensure that your implementation adheres to Rust best practices and includes appropriate documentation for public APIs. Store your implementation in the /app/ directory of the project.