随笔分类 - Rust
摘要:原理 通过宏实现,代码来自 macro-log: use proc_macro::TokenStream; use quote::quote; use syn::LitStr; pub fn read_dir(args: TokenStream) -> TokenStream { let path
阅读全文
摘要:# async 观察代码: ``` async fn dd(a: i32) -> i32 { dbg!(a); 2 * a } ``` 异步方法内可以执行await,很显然上面的代码等价于下面两种形式: ``` async fn dd(a: i32) -> i32 { dbg!(a); async
阅读全文
摘要:# 资料 Rust 程序设计语言 Book:https://doc.rust-lang.org/book/ Rust Book本地:`rustup docs --book` Rust 程序设计语言 简体中文版:https://kaisery.github.io/trpl-zh-cn/ Rust Bo
阅读全文
摘要:# #[tokio::test] 运行时 `#[tokio::test]` 运行时和 `#[tokio::main]` 的默认值是不一样的,前者默认单线程,后者默认多线程: > The default test runtime is single-threaded. 所以有的时候运行和测试的结果可能
阅读全文
摘要:# (&mut Future).await 直接执行 `join_handle.await` 会消费 JoinHandle ,通过 `(&mut join_handle).await` 不消费 JoinHandle ,参考:https://github.com/tokio-rs/tokio/disc
阅读全文
摘要:添加target:wasm32-unknown-unknown rustup target add wasm32-unknown-unknown info: downloading component 'rust-std' for 'wasm32-unknown-unknown' info: ins
阅读全文
摘要:尝试修改项目 Cargo.toml [dependencies] openssl = { version = "0.10", features = ["vendored"] } https://github.com/sfackler/rust-openssl/issues/1021 无效,因为是执行
阅读全文
摘要:问题描述 构建时间较长,文件较大 Finished dev [unoptimized + debuginfo] target(s) in 24.36s real 0m24.724s user 0m10.158s sys 0m2.687s ubuntu@VM-12-10-ubuntu:~/test/t
阅读全文
摘要:Cargo.toml [package] name = "static_link" version = "0.1.0" authors = ["develon <develon@qq.com>"] edition = "2018" build = "build.rs" # See more keys
阅读全文
摘要:git-fetch-with-cli [net] git-fetch-with-cli = true 查询命令行: wmic:root\cli>process where caption="git.exe" get ExecutablePath, caption, CommandLine Capti
阅读全文
摘要:# 添加编译目标 首先明确一下,Rust 有个平台支持等级的概念,处于等级1的平台可以使用 `rustup default [stable-x86_64-pc-windows-msvc]` 设置为主机平台,其它等级的只能使用以下方式设置为编译目标: ``` rustup target add aar
阅读全文
摘要:bincode fn bin<T>(p: &T) { bin2(p, std::mem::size_of_val(p) as i8); } fn bin2<T>(p: *const T, le: i8) { let p = p as *const u8; println!("show {:p}, c
阅读全文
摘要:研究性代码 alert('doo'); #[no_mangle] // extern "C" fn using(f: extern "C" fn()) { extern "C" fn using(f: *const u8) { let a = (&f) as *const _ as *const f
阅读全文
摘要:使用 cmake 的局限性 .lib 合并问题 cmake 不会将多个 .lib 合并, 因此可能需要使用 add_custom_command 命令手动使用 MSVC 工具 lib.exe 来创建最终具有 C ABI 的 .lib 静态库文件供Rust调用. set(Target "output"
阅读全文
摘要:设置cfg选项以有条件地进行编译 RUSTFLAGS='--cfg buffersize="32"' cargo build see 关于rust - 如何设置cfg选项以有条件地进行编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com
阅读全文