rxing/client/result/
VINParsedResult.rs

1/*
2 * Copyright 2014 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
17// package com.google.zxing.client.result;
18
19use super::{ParsedRXingResult, ParsedRXingResultType};
20
21/**
22 * Represents a parsed result that encodes a Vehicle Identification Number (VIN).
23 */
24#[derive(PartialEq, Eq, Hash, Debug)]
25pub struct VINParsedRXingResult {
26    vin: String,
27    world_manufacturer_id: String,
28    vehicle_descriptor_section: String,
29    vehicle_identifier_section: String,
30    country_code: String,
31    vehicle_attributes: String,
32    model_year: u32,
33    plant_code: char,
34    sequential_number: String,
35}
36
37impl ParsedRXingResult for VINParsedRXingResult {
38    fn getType(&self) -> super::ParsedRXingResultType {
39        ParsedRXingResultType::Vin
40    }
41
42    fn getDisplayRXingResult(&self) -> String {
43        let mut result = String::with_capacity(50);
44        result.push_str(&self.world_manufacturer_id);
45        result.push(' ');
46        result.push_str(&self.vehicle_descriptor_section);
47        result.push(' ');
48        result.push_str(&self.vehicle_identifier_section);
49        result.push('\n');
50        if !self.country_code.is_empty() {
51            result.push_str(&self.country_code);
52            result.push(' ');
53        }
54        result.push_str(&self.model_year.to_string());
55        result.push(' ');
56        result.push(self.plant_code);
57        result.push(' ');
58        result.push_str(&self.sequential_number);
59        result.push('\n');
60
61        result
62    }
63}
64impl VINParsedRXingResult {
65    #[allow(clippy::too_many_arguments)]
66    pub fn new(
67        vin: String,
68        world_manufacturer_id: String,
69        vehicle_descriptor_section: String,
70        vehicle_identifier_section: String,
71        country_code: String,
72        vehicle_attributes: String,
73        model_year: u32,
74        plant_code: char,
75        sequential_number: String,
76    ) -> Self {
77        Self {
78            vin,
79            world_manufacturer_id,
80            vehicle_descriptor_section,
81            vehicle_identifier_section,
82            country_code,
83            vehicle_attributes,
84            model_year,
85            plant_code,
86            sequential_number,
87        }
88    }
89
90    pub fn getVIN(&self) -> &str {
91        &self.vin
92    }
93
94    pub fn getWorldManufacturerID(&self) -> &str {
95        &self.world_manufacturer_id
96    }
97
98    pub fn getVehicleDescriptorSection(&self) -> &str {
99        &self.vehicle_descriptor_section
100    }
101
102    pub fn getVehicleIdentifierSection(&self) -> &str {
103        &self.vehicle_identifier_section
104    }
105
106    pub fn getCountryCode(&self) -> &str {
107        &self.country_code
108    }
109
110    pub fn getVehicleAttributes(&self) -> &str {
111        &self.vehicle_attributes
112    }
113
114    pub fn getModelYear(&self) -> u32 {
115        self.model_year
116    }
117
118    pub fn getPlantCode(&self) -> char {
119        self.plant_code
120    }
121
122    pub fn getSequentialNumber(&self) -> &str {
123        &self.sequential_number
124    }
125}