rxing/oned/rss/expanded/
expanded_row.rs

1/*
2 * Copyright (C) 2010 ZXing authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use std::{fmt::Display, hash::Hash};
18
19use super::ExpandedPair;
20
21/**
22 * One row of an RSS Expanded Stacked symbol, consisting of 1+ expanded pairs.
23 */
24#[derive(Clone)]
25pub struct ExpandedRow {
26    pairs: Vec<ExpandedPair>,
27    rowNumber: u32,
28}
29impl ExpandedRow {
30    pub const fn new(pairs: Vec<ExpandedPair>, rowNumber: u32) -> Self {
31        Self { pairs, rowNumber }
32    }
33
34    pub fn getPairs(&self) -> &[ExpandedPair] {
35        &self.pairs
36    }
37
38    #[cfg(all(test, feature = "image"))]
39    pub(crate) fn getPairsMut(&mut self) -> &mut [ExpandedPair] {
40        &mut self.pairs
41    }
42
43    pub fn getRowNumber(&self) -> u32 {
44        self.rowNumber
45    }
46
47    pub fn isEquivalent(&self, otherPairs: &[ExpandedPair]) -> bool {
48        self.pairs == otherPairs
49    }
50}
51
52impl PartialEq for ExpandedRow {
53    /**
54     * Two rows are equal if they contain the same pairs in the same order.
55     */
56    fn eq(&self, other: &Self) -> bool {
57        self.pairs == other.pairs
58    }
59}
60
61impl Hash for ExpandedRow {
62    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
63        self.pairs.hash(state);
64    }
65}
66
67impl Display for ExpandedRow {
68    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69        write!(f, "{{ ")?;
70        for p in &self.pairs {
71            write!(f, "{p}")?;
72        }
73        write!(f, " }}") //{:?} }} " , self.pairs )
74    }
75}