cleanup
This commit is contained in:
parent
cce932400a
commit
592a67a304
@ -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());
|
||||
|
||||
@ -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},
|
||||
};
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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)
|
||||
|
||||
13
src/misc.rs
13
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::<Vec<u8>, 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::<Vec<u8>, String>([self, data].concat()) }
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
@ -206,4 +211,4 @@ pub fn random_u64() -> Result<u64, getrandom::Error> {
|
||||
|
||||
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) }
|
||||
|
||||
@ -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::<Vec<u8>>();
|
||||
let data = "really cool data"
|
||||
.chars()
|
||||
.map(|c| c as u8)
|
||||
.collect::<Vec<u8>>();
|
||||
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!(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user