diff --git a/src/function_manager.rs b/src/function_manager.rs index 224a70b..cbfa58b 100644 --- a/src/function_manager.rs +++ b/src/function_manager.rs @@ -115,7 +115,7 @@ impl FunctionManager { ); // Only keep valid chars - new_string.retain(|c| crate::misc::is_valid_char(&c)); + new_string.retain(|c| crate::misc::is_valid_char(c)); // If not fully open, return here as buttons cannot yet be displayed, therefore the user is inable to mark it for deletion let animate_bool = ui.ctx().animate_bool(te_id, re.has_focus()); diff --git a/src/lib.rs b/src/lib.rs index 80bdc0f..788cc80 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,7 @@ #![feature(const_slice_index)] #![feature(slice_split_at_unchecked)] #![feature(inline_const)] +#![feature(const_for)] #[macro_use] extern crate static_assertions; @@ -26,13 +27,14 @@ pub use crate::{ function_entry::{FunctionEntry, Riemann}, math_app::AppSettings, misc::{ - // decimal_round, - hashed_storage_create, hashed_storage_read, newtons_method, option_vec_printer, step_helper, EguiHelper, + // decimal_round, + // hashed_storage_create, + HashBytesHelper, }, unicode_helper::{to_chars_array, to_unicode_hash}, }; diff --git a/src/main.rs b/src/main.rs index ccc89b6..973b744 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ #![feature(const_slice_index)] #![feature(slice_split_at_unchecked)] #![feature(inline_const)] +#![feature(const_for)] #[macro_use] extern crate static_assertions; diff --git a/src/math_app.rs b/src/math_app.rs index 3bf870b..ac600f9 100644 --- a/src/math_app.rs +++ b/src/math_app.rs @@ -1,5 +1,8 @@ use crate::{ - consts::*, function_entry::Riemann, function_manager::FunctionManager, misc::option_vec_printer, + consts::*, + function_entry::Riemann, + function_manager::FunctionManager, + misc::{option_vec_printer, HashBytesHelper}, }; use eframe::App; use egui::{ @@ -214,7 +217,7 @@ impl MathApp { std::mem::transmute::<&str, crate::misc::HashBytes>(build::SHORT_COMMIT) } }; - let saved_data = &crate::misc::hashed_storage_create(&commit, data); + let saved_data = commit.hashed_storage_create(data); tracing::info!("Bytes: {}", saved_data.len()); get_localstorage() .set_item(DATA_NAME, saved_data) diff --git a/src/misc.rs b/src/misc.rs index 1d3b53a..e7e04d2 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -172,9 +172,14 @@ pub const HASH_LENGTH: usize = 8; /// Represents bytes used to represent hash info pub type HashBytes = [u8; HASH_LENGTH]; -#[allow(dead_code)] -pub fn hashed_storage_create(hash: &HashBytes, data: &[u8]) -> String { - unsafe { std::mem::transmute::, String>([hash, data].concat()) } +pub trait HashBytesHelper { + fn hashed_storage_create(&self, data: &[u8]) -> String; +} + +impl HashBytesHelper for HashBytes { + fn hashed_storage_create(&self, data: &[u8]) -> String { + unsafe { std::mem::transmute::, String>([self, data].concat()) } + } } #[allow(dead_code)] @@ -206,4 +211,4 @@ pub fn random_u64() -> Result { include!(concat!(env!("OUT_DIR"), "/valid_chars.rs")); -pub fn is_valid_char(c: &char) -> bool { c.is_alphanumeric() | VALID_EXTRA_CHARS.contains(c) } +pub fn is_valid_char(c: char) -> bool { c.is_alphanumeric() | VALID_EXTRA_CHARS.contains(&c) } diff --git a/tests/misc.rs b/tests/misc.rs index dc33cc5..5986c11 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -62,20 +62,18 @@ fn option_vec_printer() { #[test] fn hashed_storage() { - use ytbn_graphing_software::{hashed_storage_create, hashed_storage_read}; + use ytbn_graphing_software::{hashed_storage_read, HashBytesHelper}; let commit = "abcdefeg".chars().map(|c| c as u8).collect::>(); let data = "really cool data" .chars() .map(|c| c as u8) .collect::>(); - let storage = hashed_storage_create( - commit - .as_slice() - .try_into() - .expect("cannot turn into [u8; 8]"), - data.as_slice(), - ); + let storage_tmp: [u8; 8] = commit + .as_slice() + .try_into() + .expect("cannot turn into [u8; 8]"); + let storage = storage_tmp.hashed_storage_create(data.as_slice()); let read = hashed_storage_read(&storage); assert_eq!(