I am working on a project that uses #![no_std]
, and I would like to be able to derive useful traits such as Copy
and Clone
. I tried adding pub use core::prelude::*;
to both the project root, and the file I actually want to use it in. However, any attempts to #[derive(Copy)]
results in
error: attempt to implement a nonexistent trait std::marker::Copy
I don't understand what I'm doing wrong. Attempting to add
use core::marker::Copy
yields this:
error: a type named Copy has already been imported in this module
#[derive]在#![no_std] pub mod std {pub use core::*;}
将修复它,它会替换::std::
with ::core::
实例,允许你导出特征编译器认为是core
std
You can always implement marker traits with impl
:
impl Copy for MyStruct {}
It will work only for marker traits though, Clone
and other similar traits still need deriving
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.