reorder main

main
Zynh0722 2023-04-12 05:09:33 -07:00
parent 0bc80831e7
commit af92f779e6
1 changed files with 29 additions and 29 deletions

View File

@ -38,6 +38,14 @@ mod state;
use state::{AppState, UploadRecord}; use state::{AppState, UploadRecord};
pub mod error {
use std::io::{Error, ErrorKind};
pub fn io_other(s: &str) -> Error {
Error::new(ErrorKind::Other, s)
}
}
#[tokio::main] #[tokio::main]
async fn main() -> io::Result<()> { async fn main() -> io::Result<()> {
// Set up logging // Set up logging
@ -162,35 +170,6 @@ fn get_random_name(len: usize) -> String {
Alphanumeric.sample_string(&mut rng, len) Alphanumeric.sample_string(&mut rng, len)
} }
#[allow(dead_code)]
static UNITS: [&str; 6] = ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB"];
// This function is actually rather interesting to me, I understand that rust is
// very powerful, and its very safe, but i find it rather amusing that the [] operator
// doesn't check bounds, meaning it can panic at runtime. Usually rust is very
// very careful about possible panics
//
// although this function shouldn't be able to panic at runtime due to known bounds
// being listened to
#[inline]
fn _bytes_to_human_readable(bytes: u64) -> String {
let mut running = bytes as f64;
let mut count = 0;
while running > 1024.0 && count <= 6 {
running /= 1024.0;
count += 1;
}
format!("{:.2} {}", running, UNITS[count - 1])
}
pub mod error {
use std::io::{Error, ErrorKind};
pub fn io_other(s: &str) -> Error {
Error::new(ErrorKind::Other, s)
}
}
async fn write_to_cache<T, Y>(records: &HashMap<T, Y>) -> io::Result<()> async fn write_to_cache<T, Y>(records: &HashMap<T, Y>) -> io::Result<()>
where where
T: Serialize, T: Serialize,
@ -221,3 +200,24 @@ async fn fetch_cache() -> AppState {
AppState::new(records) AppState::new(records)
} }
#[allow(dead_code)]
static UNITS: [&str; 6] = ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB"];
// This function is actually rather interesting to me, I understand that rust is
// very powerful, and its very safe, but i find it rather amusing that the [] operator
// doesn't check bounds, meaning it can panic at runtime. Usually rust is very
// very careful about possible panics
//
// although this function shouldn't be able to panic at runtime due to known bounds
// being listened to
#[inline]
fn _bytes_to_human_readable(bytes: u64) -> String {
let mut running = bytes as f64;
let mut count = 0;
while running > 1024.0 && count <= 6 {
running /= 1024.0;
count += 1;
}
format!("{:.2} {}", running, UNITS[count - 1])
}