cbsk_base

Crates.iocbsk_base
lib.rscbsk_base
version
sourcesrc
created_at2023-12-13 04:27:47.00378+00
updated_at2025-02-12 03:09:31.932225+00
descriptioncbsk_base is a locked version cargo crates
homepage
repositoryhttps://github.com/lifeRobot/cbsk/tree/master/libs/cbsk_base
max_upload_size
id1067663
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
(lifeRobot)

documentation

README

cbsk_base is a locked version cargo crates
you can use cbsk_base lock commonly used cargo crates versions
cbsk_base also supports some custom trait, like ToJson,FromJson and some macro

now locked version

name git version
tokio github 1.43.0
anyhow github 1.0.95
once_cell github 1.20.3
serde github 1.0.217
serde_json github 1.0.138
log github 0.4.25
async-trait github 0.1.86
async-recursion github 1.1.1
parking_lot github 0.12.3
fastdate github 0.3.34

serde example

use serde_derive_json,
the struct impl Serialize, will auto impl ToJson
the struct impl Deserialize, will auto impl FromJson

Cargo.toml file :

cbsk_base = { version = "2.1.1", features = ["serde_derive_json"] }

main.rs file :

use cbsk_base::json::from_json::FromJson;
use cbsk_base::json::to_json::ToJson;
use cbsk_base::serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Default, Debug)]
#[serde(crate = "cbsk_base::serde")]
struct A {
    data: String,
}

fn main() {
    let a = A::default();
    let json = a.to_json();
    println!("a is {json:?}"); // a is Ok(Object {"data": String("")})

    let a = A::from_json(json.unwrap());
    println!("a is {a:?}"); // a is Ok(A { data: "" })
}

option macro example

Cargo.toml file :

cbsk_base = { version = "2.1.1", features = ["macro", "anyhow"] }

main.rs file :

use cbsk_base::anyhow;

fn main() {
    let a = try_get_option();
    println!("a is {a:?}"); // a is Ok("hello world")
    exec_option();
}

fn try_get_option() -> anyhow::Result<String> {
    let a = Some("hello world".to_string());
    // match Option if is Some,
    // will be return value if is Nome,
    // will be return custom value and exit method
    Ok(cbsk_base::match_some_return!(a,Err(anyhow::anyhow!("a is none"))))
}

fn exec_option() {
    let a = Some("hello world".to_string());
    // match Option if is Some,
    // will be return value if is Nome,
    // will be return custom value
    let a = cbsk_base::match_some_exec!(a,{
        // do something, you can exit method, or break String
        println!("a is None");// will not output, because a not None
        return;
    });
    println!("a is {a}"); // a is hello world
}

root_path example

Cargo.toml file:

cbsk_base = { version = "2.1.1", features = ["root_path"] }

main.rs file:

fn main() {
    // print the path where the program is located
    let root_path = cbsk_base::root_path();
    println!("root path is {root_path}");
}
Commit count: 112

cargo fmt