1 Star 0 Fork 0

EternalNight / e-utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT
e-utils

📄 中文 | 📄 English

⚡ what this ?

This is a universal feature library that integrates convenient features

Support app

APP

Windows 10

Unix

Macos

Uuid

Base64

Algorithm

GUI

×

×

Image

cmd

_

×

×

×

✨ Features

[features]
std = []
alloc = []
fs = []
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"]
default = ["std"]

📖 Example

[dependencies]
e-utils = {version="0.3.0", feature=["algorithm"]}
 // 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));
 }
[dependencies]
e-utils = {version="0.3.0", feature=["algorithm","images"]}

Example Image save from Memory then switch to base64

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<T>(
  pic_buf_ptr: *const T,
  buf_size: usize,
  cache_dir: PathBuf,
  store: &Store,
) -> Result<Value> {
  // 从内存中获取数据
  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

MIT License Copyright (c) 2024 EternalNight Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

集成便捷库 展开 收起
Rust
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Rust
1
https://gitee.com/eternalnight996/e-utils.git
git@gitee.com:eternalnight996/e-utils.git
eternalnight996
e-utils
e-utils
master

搜索帮助