From fb2a5e8c02d07aaa9d83bfff4eb05fb8d66e7a9e Mon Sep 17 00:00:00 2001 From: endernon Date: Sat, 11 Jan 2025 00:20:37 +0000 Subject: [PATCH] Add return Result<(),Errorfr> for everything just for the sake of future proofing --- src/encode.rs | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/src/encode.rs b/src/encode.rs index e6f3f62..743a6fd 100644 --- a/src/encode.rs +++ b/src/encode.rs @@ -14,7 +14,7 @@ use idmangler_lib::{ use idmangler_lib::encoding::DataEncoder; use std::collections::HashMap; -pub fn encode_startdata(general_params: &mut FuncParams) { +pub fn encode_startdata(general_params: &mut FuncParams) -> Result<(), Errorfr> { if *general_params.fr_debug_mode { println!("Encoding StartData") } @@ -22,8 +22,9 @@ pub fn encode_startdata(general_params: &mut FuncParams) { StartData(general_params.fr_ver) .encode(general_params.fr_ver, general_params.fr_out) .unwrap(); + Ok(()) } -pub fn encode_typedata(general_params: &mut FuncParams, item_type_deser: ItemTypeDeser) { +pub fn encode_typedata(general_params: &mut FuncParams, item_type_deser: ItemTypeDeser) -> Result<(), Errorfr> { if *general_params.fr_debug_mode { println!("Encoding TypeData: {:?}", item_type_deser); } @@ -31,11 +32,9 @@ pub fn encode_typedata(general_params: &mut FuncParams, item_type_deser: ItemTyp TypeData(ItemType::from(item_type_deser)) .encode(general_params.fr_ver, general_params.fr_out) .unwrap(); + Ok(()) } -pub fn encode_typedata_custom( - general_params: &mut FuncParams, - crafted_type: &str, -) -> Result<(), Errorfr> { +pub fn encode_typedata_custom(general_params: &mut FuncParams, crafted_type: &str) -> Result<(), Errorfr> { let frfr_type = CraftedTypesFr::try_from(crafted_type)?; match frfr_type { CraftedTypesFr::Gear(a) => { @@ -57,10 +56,7 @@ pub fn encode_typedata_custom( } Ok(()) } -pub fn encode_duradata( - general_params: &mut FuncParams, - real_dura: &Durability, -) -> Result<(), Errorfr> { +pub fn encode_duradata(general_params: &mut FuncParams, real_dura: &Durability) -> Result<(), Errorfr> { let effect_strength_fr: u8; // but actually it should be 0 to 100, not 0 to 255. But i dunno how to use u7 data type. if let Some(effstr) = real_dura.effect_strength { if *general_params.fr_debug_mode { @@ -115,7 +111,7 @@ pub fn encode_duradata( .unwrap(); Ok(()) } -pub fn encode_reqdata(general_params: &mut FuncParams, real_reqdata: RequirementsDeser) { +pub fn encode_reqdata(general_params: &mut FuncParams, real_reqdata: RequirementsDeser) -> Result<(), Errorfr> { if *general_params.fr_debug_mode { println!( "Encoding RequirementData.Level: {:?}", @@ -145,9 +141,10 @@ pub fn encode_reqdata(general_params: &mut FuncParams, real_reqdata: Requirement skills: spvec, } .encode(general_params.fr_ver, general_params.fr_out) - .unwrap() + .unwrap(); + Ok(()) } -pub fn encode_namedata(general_params: &mut FuncParams, real_name: &str) { +pub fn encode_namedata(general_params: &mut FuncParams, real_name: &str) -> Result<(), Errorfr> { // ENCODE: NameData if *general_params.fr_debug_mode { println!("Encoding NameData: {:?}", &real_name) @@ -155,12 +152,9 @@ pub fn encode_namedata(general_params: &mut FuncParams, real_name: &str) { NameData(real_name.trim().to_string()) .encode(general_params.fr_ver, general_params.fr_out) .unwrap(); + Ok(()) } -pub fn encode_iddata( - general_params: &mut FuncParams, - real_ids: &Vec, - idsmap: HashMap, -) { +pub fn encode_iddata(general_params: &mut FuncParams, real_ids: &Vec, idsmap: HashMap) -> Result<(), Errorfr> { let mut idvec = Vec::new(); for eachid in real_ids { let id_id = idsmap.get(eachid.id.trim()); @@ -193,6 +187,7 @@ pub fn encode_iddata( } .encode(general_params.fr_ver, general_params.fr_out) .unwrap(); + Ok(()) } pub fn encode_powderdata(general_params: &mut FuncParams, real_powders: &Vec) -> Result<(), Errorfr> { let mut powdervec = Vec::new(); @@ -233,7 +228,7 @@ pub fn encode_powderdata(general_params: &mut FuncParams, real_powders: &Vec Result<(), Errorfr> { if rerollcount != 0 { // ENCODE: RerollData if applicable RerollData(rerollcount) @@ -243,12 +238,9 @@ pub fn encode_rerolldata(general_params: &mut FuncParams, rerollcount: u8) { dbg!(rerollcount); } } + Ok(()) } -pub fn encode_shinydata( - general_params: &mut FuncParams, - shiny: &Shinyjson, - json_shiny: &Vec, -) { +pub fn encode_shinydata(general_params: &mut FuncParams, shiny: &Shinyjson, json_shiny: &Vec) -> Result<(), Errorfr> { let mut realshinykey: u8; let _shinykey = &shiny.key; let shinyvalue = shiny.value; @@ -272,8 +264,9 @@ pub fn encode_shinydata( } .encode(general_params.fr_ver, general_params.fr_out) .unwrap(); + Ok(()) } -pub fn encode_enddata(general_params: &mut FuncParams) { +pub fn encode_enddata(general_params: &mut FuncParams) -> Result<(), Errorfr> { if *general_params.fr_debug_mode { println!("Encoding EndData") } @@ -281,4 +274,5 @@ pub fn encode_enddata(general_params: &mut FuncParams) { EndData .encode(general_params.fr_ver, general_params.fr_out) .unwrap(); + Ok(()) }