mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
rename helper methods
This commit is contained in:
@@ -35,16 +35,16 @@ pub fn detect_in_svg_with_hints(
|
||||
|
||||
let path = PathBuf::from(file_name);
|
||||
if !path.exists() {
|
||||
return Err(Exceptions::illegalArgument("file does not exist"));
|
||||
return Err(Exceptions::illegalArgumentWith("file does not exist"));
|
||||
}
|
||||
|
||||
let Ok(mut file) = File::open(path) else {
|
||||
return Err(Exceptions::illegalArgument("file cannot be opened"));
|
||||
return Err(Exceptions::illegalArgumentWith("file cannot be opened"));
|
||||
};
|
||||
|
||||
let mut svg_data = Vec::new();
|
||||
if file.read_to_end(&mut svg_data).is_err() {
|
||||
return Err(Exceptions::illegalArgument("file cannot be read"));
|
||||
return Err(Exceptions::illegalArgumentWith("file cannot be read"));
|
||||
}
|
||||
|
||||
let mut multi_format_reader = MultiFormatReader::default();
|
||||
@@ -84,16 +84,16 @@ pub fn detect_multiple_in_svg_with_hints(
|
||||
|
||||
let path = PathBuf::from(file_name);
|
||||
if !path.exists() {
|
||||
return Err(Exceptions::illegalArgument("file does not exist"));
|
||||
return Err(Exceptions::illegalArgumentWith("file does not exist"));
|
||||
}
|
||||
|
||||
let Ok(mut file) = File::open(path) else {
|
||||
return Err(Exceptions::illegalArgument("file cannot be opened"));
|
||||
return Err(Exceptions::illegalArgumentWith("file cannot be opened"));
|
||||
};
|
||||
|
||||
let mut svg_data = Vec::new();
|
||||
if file.read_to_end(&mut svg_data).is_err() {
|
||||
return Err(Exceptions::illegalArgument("file cannot be read"));
|
||||
return Err(Exceptions::illegalArgumentWith("file cannot be read"));
|
||||
}
|
||||
|
||||
let multi_format_reader = MultiFormatReader::default();
|
||||
@@ -126,7 +126,7 @@ pub fn detect_in_file_with_hints(
|
||||
hints: &mut DecodingHintDictionary,
|
||||
) -> Result<RXingResult, Exceptions> {
|
||||
let Ok(img) = image::open(file_name) else {
|
||||
return Err(Exceptions::illegalArgument(format!("file '{file_name}' not found or cannot be opened")));
|
||||
return Err(Exceptions::illegalArgumentWith(format!("file '{file_name}' not found or cannot be opened")));
|
||||
};
|
||||
let mut multi_format_reader = MultiFormatReader::default();
|
||||
|
||||
@@ -160,7 +160,7 @@ pub fn detect_multiple_in_file_with_hints(
|
||||
hints: &mut DecodingHintDictionary,
|
||||
) -> Result<Vec<RXingResult>, Exceptions> {
|
||||
let img = image::open(file_name)
|
||||
.map_err(|e| Exceptions::runtime(format!("couldn't read {file_name}: {e}")))?;
|
||||
.map_err(|e| Exceptions::runtimeWith(format!("couldn't read {file_name}: {e}")))?;
|
||||
let multi_format_reader = MultiFormatReader::default();
|
||||
let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader);
|
||||
|
||||
@@ -247,7 +247,7 @@ pub fn save_image(file_name: &str, bit_matrix: &BitMatrix) -> Result<(), Excepti
|
||||
let image: image::DynamicImage = bit_matrix.into();
|
||||
match image.save(file_name) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => Err(Exceptions::illegalArgument(format!(
|
||||
Err(err) => Err(Exceptions::illegalArgumentWith(format!(
|
||||
"could not save file '{file_name}': {err}"
|
||||
))),
|
||||
}
|
||||
@@ -259,7 +259,7 @@ pub fn save_svg(file_name: &str, bit_matrix: &BitMatrix) -> Result<(), Exception
|
||||
|
||||
match svg::save(file_name, &svg) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => Err(Exceptions::illegalArgument(format!(
|
||||
Err(err) => Err(Exceptions::illegalArgumentWith(format!(
|
||||
"could not save file '{}': {}",
|
||||
file_name, err
|
||||
))),
|
||||
@@ -294,7 +294,7 @@ pub fn save_file(file_name: &str, bit_matrix: &BitMatrix) -> Result<(), Exceptio
|
||||
Ok(())
|
||||
}() {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err(Exceptions::illegalArgument(format!(
|
||||
Err(_) => Err(Exceptions::illegalArgumentWith(format!(
|
||||
"could not write to '{file_name}'"
|
||||
))),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user