惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
J
Java Code Geeks
量子位
腾讯CDC
C
Check Point Blog
小众软件
小众软件
IT之家
IT之家
I
InfoQ
Hugging Face - Blog
Hugging Face - Blog
Stack Overflow Blog
Stack Overflow Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
GbyAI
GbyAI
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
博客园_首页
S
SegmentFault 最新的问题
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
Martin Fowler
Martin Fowler

The Rust Programming Language Forum - Latest topics

Beginner building a Rust backend framework (AI-assisted) — feedback appreciated C++ to Rust -- Exceptions Re-exporting a trait with a custom derive_macro Gold linker is deprecated Why is using PhantomData valid in this case? Code review for Static Pool Allocator Looking for a pool based allocator Why is this legal? What does it mean for Rustc to run "out of TLS keys"? Using async/await internally with no internal runtime, but exposing a nonblocking poll API — is this a reasonable design? Testing functions that use randomness `cargo-path`: improve coding agents&#39; ability to find Rust documentation Rust task runners Lifetime weird case Windows - USB device not detected A random rustc-ice-[...].txt file appeared Develop rust where the environment is setup in a docker Undefined Behavior: in-bounds pointer arithmetic failed: attempting to offset pointer by 20 bytes, but got alloc238 which is only 1 byte from the end of the allocation Unbug 0.5 - Runtime debug assertions Is there a tiny error in section 6.2 Reference types? Lifetime woes implementing ratatui::Widget for a reference Rusqlite + Chrono: How do I simplify code to obtain chrono datetime value From OOP to Rust – struggling with code organization and data structure design Way to avoid a self-referential struct Rust RF and audio resources/communities Whyhttp - HTTP mocks that fail where the bug actually is Using tokio channel permits in a tower service Arc::increment_strong_count design question (cross-post) `&T`, `&mut T`, `Pin<&mut T>` and `&Cell<T>`: Ways of Borrowing a `T` Ratatui detect arrow key press and release
Borsh v1.6.1 example
Jit-coder-58 · 2026-04-20 · via The Rust Programming Language Forum - Latest topics

Here is the link for borsh v1.6.1 page (crates.io: Rust Package Registry). I tried to use the code example posted in the page and got several compilation errors. I added dependency in rust Cargo.toml file, as suggested, and the code:
[dependencies]
borsh = "1.6.1"
borsh-derive = "1.6.1"

#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)]
struct A {
    x: u64,
    y: String,
}

fn main() {
    let a = A {
        x: 3301,
        y: "liber primus".to_string(),
    };
    let encoded_a = to_vec(&a).unwrap();
    println!("Encoded serialization : {encoded_a:?}");
    let decoded_a = from_slice::<A>(&encoded_a).unwrap();
    println!("Decoded serialization: {decoded_a:?}");
    assert_eq!(a, decoded_a);
}

Some of the errors are posted below:
cannot find derive macro BorshSerialize in this scope
--> src\main.rs:3:10
|
3 | #[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)]
| ^^^^^^^^^^^^^^
|
note: BorshSerialize is imported here, but it is only a trait, without a derive macro
--> src\main.rs:1:13
|
1 | use borsh::{BorshSerialize, BorshDeserialize, from_slice, to_vec};
| ^^^^^^^^^^^^^^

error: cannot find derive macro BorshDeserialize in this scope
--> src\main.rs:3:26
|
3 | #[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)]
| ^^^^^^^^^^^^^^^^
|
note: BorshDeserialize is imported here, but it is only a trait, without a derive macro
--> src\main.rs:1:29
|
1 | use borsh::{BorshSerialize, BorshDeserialize, from_slice, to_vec};
| ^^^^^^^^^^^^^^^^

error[E0277]: the trait bound A: BorshSerialize is not satisfied
--> src\main.rs:14:28
|
14 | let encoded_a = to_vec(&a).unwrap();
| ------ ^^ unsatisfied trait bound
| |
| required by a bound introduced by this call
|
help: the trait BorshSerialize is not implemented for A
--> src\main.rs:4:1 and so on...

However, If I specifically import borsh_derive (se borsh_derive::{BorshSerialize, BorshDeserialize}:wink: and add vector type (let encoded_a: Vec = to_vec(&a).unwrap(), the errors go awasy and the code is compiled.