
Rust
Rust programming
金庆
这个作者很懒,什么都没留下…
展开
-
Rust Closure Variable Capture
【代码】Rust Closure Variable Capture。原创 2025-01-21 12:04:09 · 380 阅读 · 0 评论 -
Convert IO traits between tokio, hyper and futures
【代码】Convert IO traits between tokio, hyper and futures。原创 2025-01-17 10:13:18 · 157 阅读 · 0 评论 -
Change Future into Async Function
Change。原创 2024-12-26 14:35:46 · 360 阅读 · 0 评论 -
Rust integration tests in a separate crate
【代码】Rust integration tests in a separate crate。转载 2024-12-17 15:44:27 · 59 阅读 · 0 评论 -
Separate Rust Unit Test
【代码】Separate Rust Unit Test。转载 2024-12-15 10:41:25 · 43 阅读 · 0 评论 -
Compare smol-hyper and hyper-futures for impl Read
【代码】Compare smol-hyper and hyper-futures for impl Read。原创 2024-11-29 15:04:12 · 337 阅读 · 0 评论 -
Inventing the Service Trait
【代码】Inventing the Service Trait。转载 2024-11-28 10:48:35 · 56 阅读 · 0 评论 -
How to set_default() using config-rs crate
【代码】How to set_default() using config-rs crate。原创 2024-11-07 20:07:06 · 569 阅读 · 0 评论 -
Return Consumed Argument on Error
【代码】Return Consumed Argument on Error。原创 2024-11-05 11:02:08 · 321 阅读 · 0 评论 -
Rust Empty Type
【代码】【无标题】原创 2024-09-19 13:46:47 · 591 阅读 · 0 评论 -
async Lifetimes
【代码】async Lifetimes。原创 2024-09-18 12:11:18 · 293 阅读 · 0 评论 -
Rust Pin
(Jin Qing’s Column, Sep., 2024)From: https://doc.rust-lang.org/std/pin/index.htmlRust can pin data location in memory, that means its address can not be changed.Pinned data guarantees the memory location is always valid.Safe code can not move pinned data原创 2024-09-14 12:10:25 · 596 阅读 · 0 评论 -
mvcc_cell code review
【代码】mvcc_cell code review。原创 2024-08-21 21:01:00 · 603 阅读 · 0 评论 -
Inline the hot call
【代码】Inline the hot call。转载 2024-07-03 17:20:04 · 94 阅读 · 0 评论 -
Naming Conventions for Traits
(Jin Qing’s Column, Jan., 2024)From: https://github.com/rust-lang/api-guidelines/discussions/28If the trait has a single self-explanatory method (or a set of nearly identical methods), name it after the method: Clone, Hash, Default, Into, Write, ToOwned, A转载 2024-01-17 08:59:48 · 165 阅读 · 0 评论 -
Using anyhow::ensure!()
【代码】Using anyhow::ensure!()原创 2023-12-13 09:03:16 · 223 阅读 · 0 评论 -
Snapshot test with insta
【代码】Snapshot test with insta。原创 2023-12-02 15:12:34 · 211 阅读 · 0 评论 -
Rust generic type parameter and `impl Trait` parameter
(Jin Qing’s Column, Jun., 2023)See: https://doc.rust-lang.org/reference/types/impl-trait.htmlGeneric type parameter and parameter are almost equivalent: is just a syntactic sugar for generic type parameter.It is a little simpler by omitting the generic原创 2023-06-20 20:04:18 · 1137 阅读 · 0 评论 -
Unity WebGL Calls Rust Wasm
【代码】Unity WebGL Calls Rust Wasm。原创 2023-05-16 09:11:14 · 691 阅读 · 0 评论 -
Implementation of user data in cursive::Cursive
【代码】Implementation of user data in cursive::Cursive。原创 2022-10-02 16:23:19 · 175 阅读 · 0 评论 -
Rust sometimes needs manual type annotation
Rust sometimes needs manual type annotation(Jin Qing’s Column, Apr., 2022)This code compiles error:trait MyCallback: FnMut(&u32) -> () { }impl<F: FnMut(&u32) -> ()> MyCallback for F { }fn process_data(mut f: impl MyCallback) ->原创 2022-04-29 10:09:27 · 219 阅读 · 0 评论 -
How to work around rustup-init failure
How to work around rustup-init failure(Jin Qing’s Column, Mar., 2022)rustup-init.exe may fail if some anti-virus software is running with realtime protection.The error message is like this after many retries:error: could not rename component file from原创 2022-03-23 20:05:08 · 907 阅读 · 0 评论 -
Closure as the function parameter
Closure as the function parameter(Jin Qing’s Column, Mar., 2022)It is best to let the function take a closure trait as the parameter instead of function pointer.fn foo(f: fn()) { f()}fn main() { foo(|| println!("hello")); let a = 123;原创 2022-03-18 15:57:15 · 668 阅读 · 0 评论 -
deadlock detection must not run as tokio task
deadlock detection must not run as tokio taskparking_lot has an experimental feature: deadlock_detection.See: https://amanieu.github.io/parking_lot/parking_lot/deadlock/index.htmluse std::thread;use std::time::Duration;use parking_lot::deadlock;// C原创 2022-02-12 11:43:33 · 724 阅读 · 0 评论 -
Tracing usage
Tracing usage(Jin Qing’s Column, Jan., 2022)Tracing is Rust log crate: https://github.com/tokio-rs/tracingThis example code output log to stdcout and file, using a log filter file,which can automatically reload on change.https://gitee.com/jinq0123/tra原创 2022-01-02 12:30:07 · 777 阅读 · 0 评论 -
Try tracing
Try tracing(Jin Qing’s Column, Dec., 2021)https://github.com/tokio-rs/tracingUsage on githubSwitch to tag tracing-0.1.29 first. The master’s examples can not build.Subscriber is renaming to collector on master.tracing::subscriber in 0.1.29 has been r原创 2022-01-01 20:13:58 · 584 阅读 · 0 评论 -
Box<dyn Trait> doesn‘t implement the trait
Box doesn’t implement the traitFrom: https://bennetthardwick.com/dont-use-boxed-trait-objects-for-struct-internals/By default a Box doesn’t implement the trait of the object it contains. This means that trying to construct PeopleZoo<Box> won’t work转载 2021-12-21 15:05:16 · 347 阅读 · 0 评论 -
建议日志 slog 改换 tracing
建议日志 slog 改换 tracing(金庆的专栏 2021.11)slog 不是立即写盘,最后的几行日志会丢失tracing 不会丢日志slog 不支持运行中动态更改日志等级tracing with_filter_reloading()examples/tower-loadslog 不支持不同包设置不同日志等级tracing 可单独打开某个模块的日志发现一次 slog panic: panicked at 'slog::Fuse Drain: Fatal(Cu原创 2021-11-24 18:14:14 · 514 阅读 · 0 评论 -
Named parameters in Rust
Named parameters in Rust(Jin Qing’s Column, Nov. 18, 2021)There is no “named function parameters” in Rust,but there is an idiom for this case.If a function needs many parameters, we can define a typewith all these parameters as fields, and implement D原创 2021-11-18 13:12:42 · 278 阅读 · 0 评论 -
Rust traits act as generic constraints
Rust traits act as generic constraints(Jin Qing’s Column, Nov. 18, 2021)Rust traits are different from interfaces of C++/Java/Go.See: https://stevedonovan.github.io/rustifications/2018/09/08/common-rust-traits.htmlRust traits are mechanism for adding b原创 2021-11-18 12:47:21 · 526 阅读 · 0 评论 -
GLIBC_2.29 not found
GLIBC_2.29 not found(Jin Qing’s Column, Nov. 4, 2021)My Rust program failed when running in docker:root@a26b49c91efb:/myapp# ldd libmyapp_py.so./libmyapp_py.so: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by ./libmyapp_py.原创 2021-11-05 09:26:04 · 6533 阅读 · 0 评论 -
Display Non-UTF-8 output
Display Non-UTF-8 output(Jin Qing’s Column, Oct. 27, 2021)Cargo build output Non-UTF-8. Use python to decode it as gbk and print.C:\Users\jinqing01>python>>> s = b'Non-UTF-8 output: \xd5\xfd\xd4\xda\xb4\xb4\xbd\xa8\xbf\xe2 E:\\gitlab\\myp原创 2021-10-27 12:16:32 · 529 阅读 · 0 评论 -
Advice for Rust library writers about Error
Advice for library writersFrom: https://blog.burntsushi.net/rust-error-handling/Idioms for Rust libraries are still forming, but if your library needs to report custom errors, then you should probably define your own error type. It’s up to you whether or转载 2021-09-02 11:23:05 · 151 阅读 · 0 评论 -
How to show the first few errors of rustc
How to show the first few errors of rustc(Jin Qing’s Column, Sep. 1, 2021)When using VS Code to develop Rust, “cargo check” output maybe thousands of lines.Use “cargo check --color=always 2>&1 | head -n100” to limit the output.Change powershell原创 2021-09-01 10:53:35 · 134 阅读 · 0 评论 -
&‘a mut self is restrictive
&'a mut self is restrictiveFrom https://github.com/pretzelhammer/rust-blog/blob/master/posts/common-rust-lifetime-misconceptions.md#5-if-it-compiles-then-my-lifetime-annotations-are-correct#[derive(Debug)]struct NumRef<'a>(&'a i32);impl&转载 2021-08-25 13:30:37 · 167 阅读 · 0 评论 -
Rust callback idiom
Rust callback idiomCode is from: https://stackoverflow.com/questions/41081240/idiomatic-callbacks-in-rustandhttps://morestina.net/blog/793/closure-lifetimes-in-ruststruct Processor<'a> { callback: Box<dyn FnMut() + 'a>,}impl<'a>原创 2021-08-24 10:18:02 · 316 阅读 · 0 评论 -
Rust variable rebinding for closure
Rust variable rebinding for closureFrom: https://rust-unofficial.github.io/patterns/idioms/pass-var-to-closure.htmlRust closure captures variables by reference by default.You can use “move” keyword to change to move variables.In most cases, some variab转载 2021-08-22 17:28:45 · 157 阅读 · 0 评论