e-utils ### 📄 [中文](docs/README.zh.md) | 📄 [English](README.md) # ⚡ what this ? **This is a universal feature library that integrates convenient features** ### Support app

APP

Windows 10

Unix

Macos

fs_ext[lock_share、lock_access、 custom_flags2、attributes2、security_qos_flags2]

x

x

Dialog

Uuid

Base64

Algorithm

GUI

×

×

Image

cmd

_

×

×

×

# ✨ Features ```toml [features] std = [] alloc = [] fs = [] fs_ext = [] uuid_v4 = ["uuid/v4", "uuid/fast-rng", "uuid/macro-diagnostics", "uuid"] base64 = [] algorithm = ["rand"] ui = ["e-macros"] macros = ["e-macros"] images = ["image"] http = ["reqwest"] http-blocking = ["reqwest/blocking"] http-json = ["reqwest/json"] cmd = ["encoding"] encode = ["encoding"] dialog = ["rfd"] default = ["std"] ``` # 📖 Example ```toml [dependencies] e-utils = {version="0.3", feature=["algorithm"]} ``` ```rust // Exmaple `Nanoid` fn main() { use e_utils::algorithm; println!("nanoid -> {}", algorithm!(nanoid)); println!("nanoid 16bytes -> {}", algorithm!(nanoid 16)); println!("nanoid 16bytes -> {}", algorithm!(nanoid 16)); println!("nanoid 10bytes [alphabet:expr] -> {}", algorithm!(nanoid 16, &['1', 'b', 'c', '7'])); println!("nanoid unsafe 10bytes -> {}", algorithm!(nanoid unsafe 10)); println!("nanoid unsafe 10bytes [alphabet:expr]-> {}", algorithm!(nanoid unsafe 10, &['1','0'])); } // Exmaple `algorithm` fn main2() { use e_utils::algorithm; println!("random bool -> {}", algorithm!()); println!("random type -> {}", algorithm!(#u32)); println!("random type[] -> {:?}", algorithm!([u32; 10])); println!("random range 0-13 -> {}", algorithm!(13)); println!("random range -> {}", algorithm!(0i32..13)); println!("random rgb range -> {:?}", algorithm!(rgb 100,255)); } ``` ```toml [dependencies] e-utils = {version="0.3", feature=["algorithm","images"]} ``` ### Example Image save from Memory then switch to base64 ```rust use std::path::PathBuf; use e_utils::{ algorithm, images::ImageSource, parse::{AutoPath as _, ParseResult as _}, Result, }; use serde_json::{json, Value}; use super::{SnPicture, Store}; /// 处理图像数据 pub fn store_save_image( pic_buf_ptr: *const T, buf_size: usize, cache_dir: PathBuf, store: &Store, ) -> Result { // 从内存中获取数据 let reader = unsafe { ImageSource::from_raw_parts_reader(pic_buf_ptr, buf_size) }?; let iformat = reader.format().res()?; let suffix = iformat.extensions_str(); let mime_type = iformat.to_mime_type(); let image = reader.decode().map_err(|e| e.to_string())?; let nanoid = algorithm!(nanoid 12); cache_dir.auto_create_dir()?; let fpath = cache_dir.join(format!("{nanoid}.{}", suffix[0])); image .save_with_format(&fpath, iformat) .map_err(|e| e.to_string())?; let base64_str = ImageSource::image_to_base64(&image, iformat)?; let data = Value::String(format!("data:{mime_type};base64,{}", base64_str)); let id = format!("image:{nanoid}"); let _ = store.lock().res()?.insert( id.clone(), serde_json::to_value(&SnPicture { fpath, suffix: suffix[0].to_string(), mime_type: mime_type.to_string(), })?, ); Ok(json!({"key": id, "value": data})) } ``` ## `💡!important:` # 🚀 fast running # 🦊 Applied Projects # 🔭 why need to e-utils? # 🙋 Reference items and materials