Reputation: 1104
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
Upvotes: 3
Views: 781
Reputation: 128131
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
.
Upvotes: 3
Reputation: 1104
#[derive] is broken in #![no_std] pub mod std {pub use core::*;}
will fix it, it replaces instances of ::std::
with ::core::
allowing you to derive traits that the compiler thinks are in std
from core
Upvotes: 3