mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
Merge branch 'main' into pr/exception_helpers
This commit is contained in:
@@ -16,7 +16,10 @@
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use crate::{common::BitMatrix, Exceptions};
|
||||
use crate::{
|
||||
common::{BitMatrix, Result},
|
||||
Exceptions,
|
||||
};
|
||||
|
||||
use super::{ErrorCorrectionLevel, FormatInformation};
|
||||
|
||||
@@ -97,23 +100,21 @@ impl Version {
|
||||
* @return Version for a QR Code of that dimension
|
||||
* @throws FormatException if dimension is not 1 mod 4
|
||||
*/
|
||||
pub fn getProvisionalVersionForDimension(
|
||||
dimension: u32,
|
||||
) -> Result<&'static Version, Exceptions> {
|
||||
pub fn getProvisionalVersionForDimension(dimension: u32) -> Result<&'static Version> {
|
||||
if dimension % 4 != 1 {
|
||||
return Err(Exceptions::formatWith("dimension incorrect"));
|
||||
}
|
||||
Self::getVersionForNumber((dimension - 17) / 4)
|
||||
}
|
||||
|
||||
pub fn getVersionForNumber(versionNumber: u32) -> Result<&'static Version, Exceptions> {
|
||||
pub fn getVersionForNumber(versionNumber: u32) -> Result<&'static Version> {
|
||||
if !(1..=40).contains(&versionNumber) {
|
||||
return Err(Exceptions::illegalArgumentWith("version out of spec"));
|
||||
}
|
||||
Ok(&VERSIONS[versionNumber as usize - 1])
|
||||
}
|
||||
|
||||
pub fn decodeVersionInformation(versionBits: u32) -> Result<&'static Version, Exceptions> {
|
||||
pub fn decodeVersionInformation(versionBits: u32) -> Result<&'static Version> {
|
||||
let mut bestDifference = u32::MAX;
|
||||
let mut bestVersion = 0;
|
||||
for i in 0..VERSION_DECODE_INFO.len() as u32 {
|
||||
@@ -142,7 +143,7 @@ impl Version {
|
||||
/**
|
||||
* See ISO 18004:2006 Annex E
|
||||
*/
|
||||
pub fn buildFunctionPattern(&self) -> Result<BitMatrix, Exceptions> {
|
||||
pub fn buildFunctionPattern(&self) -> Result<BitMatrix> {
|
||||
let dimension = self.getDimensionForVersion();
|
||||
let mut bitMatrix = BitMatrix::with_single_dimension(dimension)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user