#locked #cbsk #cargo #traits #version #macro #tokio

cbsk_base

cbsk_base is a locked version cargo crates

16 stable releases

Uses new Rust 2024

new 2.1.2 Mar 21, 2025
2.1.0 Dec 30, 2024
2.0.6 Nov 15, 2024
1.3.11 Aug 19, 2024
0.1.4 Dec 27, 2023

#4 in #locked

Download history 38/week @ 2024-11-27 46/week @ 2024-12-04 33/week @ 2024-12-11 14/week @ 2024-12-18 131/week @ 2024-12-25 37/week @ 2025-01-01 19/week @ 2025-01-08 8/week @ 2025-01-15 1/week @ 2025-01-22 8/week @ 2025-01-29 8/week @ 2025-02-05 226/week @ 2025-02-12 23/week @ 2025-02-19 97/week @ 2025-02-26 14/week @ 2025-03-12

152 downloads per month
Used in 14 crates

MIT/Apache

22KB
353 lines

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.44.1
anyhow github 1.0.97
once_cell github 1.21.1
serde github 1.0.219
serde_json github 1.0.140
log github 0.4.26
async-trait github 0.1.88
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.2", 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.2", 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.2", 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}");
}

Dependencies

~0–8.5MB
~70K SLoC