【发布时间】:2021-09-22 10:09:47
【问题描述】:
尝试通过 Solana 程序构建时,我收到此错误。谁能告诉我如何序列化字符串,因为我在我的结构中使用字符串。或者,如果在 Solana 程序中无法序列化字符串,我应该使用什么来代替 String?
结构:盒子
#[derive(Clone, Debug, BorshSerialize, BorshDeserialize, PartialEq)]
pub struct Box {
pub token_uris: [String; 3],
pub count: i32,
pub title: String,
pub description: String,
pub image: String,
pub price: i32,
pub usd_price: i32,
pub count_nft: i32,
pub is_opened: bool,
}
错误日志:
15 | #[derive(Clone, Debug, BorshSerialize, BorshDeserialize, PartialEq)]
| ^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `std::string::String`
|
= note: required because of the requirements on the impl of `AnchorDeserialize` for `[std::string::String; 3]`
= help: see issue #48214
= note: this error originates in the derive macro `BorshDeserialize` (in Nightly builds, run with -Z macro-backtrace for more info)
【问题讨论】:
-
你能把这个问题发更多吗?
-
嗨@Netwave 不确定您所说的 mre 是什么意思,您的意思是发布导致此问题的“结构”吗?刚刚将其添加到我的问题中,请检查
-
MRE = minimal reproducible example,一种让准助手不必发明或直觉与手头的问题可能或可能没有任何关系的事物的方法。创建 MRE 的过程通常还可以引导潜在的提问者找到他们请求的答案,因为这需要更好地了解错误情况和正在发生的事情。
-
调用你的结构“盒子”并不理想,因为
Box有一个固有的 Rust 定义 -
对,我已经修好了。谢谢:)
标签: string serialization rust deserialization solana