Update macro and cargo fmt

This commit is contained in:
Steve Cook
2023-03-01 13:43:21 -05:00
parent 51fcc98b34
commit b561bd77c3
19 changed files with 101 additions and 64 deletions

View File

@@ -259,18 +259,13 @@ impl MinimalEncoder {
position: usize,
edge: Option<Rc<Edge>>,
) -> Result<()> {
let vertexIndex = position
+ edge
.as_ref()
.ok_or(Exceptions::FORMAT)?
.characterLength as usize;
let modeEdges = &mut edges[vertexIndex][edge
.as_ref()
.ok_or(Exceptions::FORMAT)?
.charsetEncoderIndex];
let modeOrdinal = Self::getCompactedOrdinal(Some(
edge.as_ref().ok_or(Exceptions::FORMAT)?.mode,
))? as usize;
let vertexIndex =
position + edge.as_ref().ok_or(Exceptions::FORMAT)?.characterLength as usize;
let modeEdges =
&mut edges[vertexIndex][edge.as_ref().ok_or(Exceptions::FORMAT)?.charsetEncoderIndex];
let modeOrdinal =
Self::getCompactedOrdinal(Some(edge.as_ref().ok_or(Exceptions::FORMAT)?.mode))?
as usize;
if modeEdges[modeOrdinal].is_none()
|| modeEdges[modeOrdinal]
.as_ref()
@@ -378,8 +373,8 @@ impl MinimalEncoder {
0,
if from + 1 >= inputLength
|| !self.canEncode(
&Mode::ALPHANUMERIC,
self.stringToEncode
&Mode::ALPHANUMERIC,
self.stringToEncode
.get(from + 1)
.ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?,
)
@@ -414,8 +409,8 @@ impl MinimalEncoder {
0,
if from + 1 >= inputLength
|| !self.canEncode(
&Mode::NUMERIC,
self.stringToEncode
&Mode::NUMERIC,
self.stringToEncode
.get(from + 1)
.ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?,
)
@@ -423,8 +418,8 @@ impl MinimalEncoder {
1
} else if from + 2 >= inputLength
|| !self.canEncode(
&Mode::NUMERIC,
self.stringToEncode
&Mode::NUMERIC,
self.stringToEncode
.get(from + 2)
.ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?,
)

View File

@@ -179,7 +179,9 @@ pub fn encode_with_hints(
version = Version::getVersionForNumber(versionNumber)?;
let bitsNeeded = calculateBitsNeeded(mode, &header_bits, &data_bits, version);
if !willFit(bitsNeeded, version, &ec_level) {
return Err(Exceptions::writer_with("Data too big for requested version"));
return Err(Exceptions::writer_with(
"Data too big for requested version",
));
}
} else {
version = recommendVersion(&ec_level, mode, &header_bits, &data_bits)?;
@@ -651,7 +653,11 @@ pub fn appendNumericBytes(content: &str, bits: &mut BitArray) -> Result<()> {
let length = content.len();
let mut i = 0;
while i < length {
let num1 = content.chars().nth(i).ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)? as u8 - b'0';
let num1 = content
.chars()
.nth(i)
.ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)? as u8
- b'0';
if i + 2 < length {
// Encode three numeric letters in ten bits.
let num2 = content
@@ -688,8 +694,12 @@ pub fn appendAlphanumericBytes(content: &str, bits: &mut BitArray) -> Result<()>
let length = content.len();
let mut i = 0;
while i < length {
let code1 =
getAlphanumericCode(content.chars().nth(i).ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)? as u32);
let code1 = getAlphanumericCode(
content
.chars()
.nth(i)
.ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)? as u32,
);
if code1 == -1 {
return Err(Exceptions::WRITER);
}