|
1 |
| -use std::fs::read_to_string; |
2 |
| - |
3 |
| -use crate::otp::otp_element::OTPElement; |
4 |
| - |
5 |
| -//no need to declare andOTP json struct cause it's the same as OTP element |
6 |
| - |
7 |
| -pub fn import(filepath: &str) -> Result<Vec<OTPElement>, String> { |
8 |
| - let file_to_import_contents = match read_to_string(filepath) { |
9 |
| - Ok(result) => result, |
10 |
| - Err(e) => return Err(format!("Error during file reading: {:?}", e)), |
11 |
| - }; |
12 |
| - let result: Result<Vec<OTPElement>, serde_json::Error> = |
13 |
| - serde_json::from_str(&file_to_import_contents); |
14 |
| - match result { |
15 |
| - Ok(element) => Ok(element), |
16 |
| - Err(e) => Err(format!("Failed to serialize file: {}", e)), |
17 |
| - } |
18 |
| -} |
| 1 | +use std::fs::read_to_string; |
| 2 | + |
| 3 | +use crate::otp::otp_element::OTPElement; |
| 4 | + |
| 5 | +//no need to declare andOTP json struct cause it's the same as OTP element |
| 6 | +pub fn import(filepath: &str) -> Result<Vec<OTPElement>, String> { |
| 7 | + let file_to_import_contents = match read_to_string(filepath) { |
| 8 | + Ok(result) => result, |
| 9 | + Err(e) => return Err(format!("Error during file reading: {:?}", e)), |
| 10 | + }; |
| 11 | + |
| 12 | + match serde_json::from_str::<Vec<OTPElement>>(&file_to_import_contents) { |
| 13 | + Ok(elements) => Ok(elements), |
| 14 | + Err(e) => Err(format!("Failed to serialize file: {}", e)), |
| 15 | + } |
| 16 | +} |
0 commit comments