removed todo!() from qrcode_version.rs

This commit is contained in:
Henry Schimke
2023-03-29 14:30:19 -05:00
parent 6a1c5c568a
commit af626afc15
3 changed files with 28 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
use crate::common::Result; use crate::common::Result;
use crate::qrcode::decoder::{Version, VersionRef, VERSION_DECODE_INFO}; use crate::qrcode::decoder::{Version, VersionRef, MICRO_VERSIONS, VERSIONS, VERSION_DECODE_INFO};
use crate::Exceptions; use crate::Exceptions;
// const Version* Version::AllMicroVersions() // const Version* Version::AllMicroVersions()
@@ -17,13 +17,28 @@ use crate::Exceptions;
impl Version { impl Version {
pub fn FromDimension(dimension: u32) -> Result<VersionRef> { pub fn FromDimension(dimension: u32) -> Result<VersionRef> {
todo!() let isMicro = dimension < 21;
// bool isMicro = dimension < 21; if (dimension % Self::DimensionStep(isMicro) != 1) {
// if (dimension % DimensionStep(isMicro) != 1) { //throw std::invalid_argument("Unexpected dimension");
// //throw std::invalid_argument("Unexpected dimension"); return Err(Exceptions::ILLEGAL_ARGUMENT);
// return nullptr; }
// } return Self::FromNumber(
// return FromNumber((dimension - DimensionOffset(isMicro)) / DimensionStep(isMicro), isMicro); (dimension - Self::DimensionOffset(isMicro)) / Self::DimensionStep(isMicro),
isMicro,
);
}
pub fn FromNumber(versionNumber: u32, is_micro: bool) -> Result<VersionRef> {
if (versionNumber < 1 || versionNumber > (if is_micro { 4 } else { 40 })) {
//throw std::invalid_argument("Version should be in range [1-40].");
return Err(Exceptions::ILLEGAL_ARGUMENT);
}
Ok(if is_micro {
&MICRO_VERSIONS[versionNumber as usize - 1]
} else {
&VERSIONS[versionNumber as usize - 1]
})
} }
pub fn DimensionOfVersion(version: u32, is_micro: bool) -> u32 { pub fn DimensionOfVersion(version: u32, is_micro: bool) -> u32 {

View File

@@ -27,8 +27,8 @@ use once_cell::sync::Lazy;
pub type VersionRef = &'static Version; pub type VersionRef = &'static Version;
static VERSIONS: Lazy<Vec<Version>> = Lazy::new(Version::buildVersions); pub static VERSIONS: Lazy<Vec<Version>> = Lazy::new(Version::buildVersions);
static MICRO_VERSIONS: Lazy<Vec<Version>> = Lazy::new(Version::build_micro_versions); pub static MICRO_VERSIONS: Lazy<Vec<Version>> = Lazy::new(Version::build_micro_versions);
/** /**
* See ISO 18004:2006 Annex D. * See ISO 18004:2006 Annex D.