diff --git a/src/commands.rs b/src/commands.rs index 52b3e25..1bcba48 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -37,7 +37,7 @@ use sha256::digest; use crate::checks::{check_file, print_checks, CheckNotice}; use crate::cli::SubCommand; -use crate::file_io::{FileError, InputFile}; +use crate::file_io::{FileError, FileReader, InputFile}; use crate::model::onkostar_editor::OnkostarEditor; use crate::profile::Profile; @@ -160,7 +160,7 @@ pub fn handle(command: SubCommand) -> Result<(), Box> { if let Some(profile) = profile { let profile = if profile.contains('.') { - InputFile::read(profile.to_string(), None)?.try_into()? + FileReader::::read(profile)? } else { Profile::embedded_profile(profile.as_str())? }; @@ -243,10 +243,8 @@ pub fn handle(command: SubCommand) -> Result<(), Box> { style(&inputfile_b).yellow() ); - let data_a: &mut OnkostarEditor = - &mut InputFile::read(inputfile_a, None)?.try_into()?; - let data_b: &mut OnkostarEditor = - &mut InputFile::read(inputfile_b, None)?.try_into()?; + let data_a = &mut FileReader::::read(inputfile_a)?; + let data_b = &mut FileReader::::read(inputfile_b)?; data_a.print_diff(data_b, strict); } diff --git a/src/file_io.rs b/src/file_io.rs index 6e7f6d3..1af9825 100644 --- a/src/file_io.rs +++ b/src/file_io.rs @@ -25,6 +25,7 @@ use std::error::Error; use std::fmt::{Debug, Display, Formatter}; use std::fs; +use std::marker::PhantomData; use std::path::Path; use std::str::FromStr; @@ -206,3 +207,20 @@ impl TryFrom for Profile { }; } } + +/// Shortcut methods for OSC and Profile files +pub struct FileReader { + file_type: PhantomData, +} + +impl FileReader { + pub fn read(filename: String) -> Result { + TryInto::::try_into(InputFile::read(filename.to_string(), None)?) + } +} + +impl FileReader { + pub fn read(filename: String) -> Result { + TryInto::::try_into(InputFile::read(filename.to_string(), None)?) + } +}