I was trying to implement Vec from the rust nomicon. But, it is failing to compile because of mainly two errrors.no oom in alloc
, that is use std::alloc::oom;
doesn't have oom
. Next use of undeclared type or module heap
. I've added this #![feature(alloc, heap_api)]
in the first line of the program. But, it's still giving me the same two errors. So, like how to import these two things?.
I don't think oom
and heap
are part of the standard library, are you sure you're looking at the latest docs?
Can you provide an example of your code on the playground?
Well, that’s the problem with unstable API (activated by those feature
flags): It’s unstable and thus can (and often will) change. This nomicon section is apparently written for an older version of rustc
. For some reason though at least the final code section is reasonably up to date. The only error it produces is on the grow
method of the AllocRef
trait, where the type of the last argument appears to have changed very recently. By removing the .size()
there, the code compiles and should work (though I’m of course not 100% sure about whether that Layout
argument is correct since I haven’t actually tried understanding the code yet).
OP is clearly referring to a part in the nomicon that does indeed refer to these parts of the standard library, but they stopped existing some time between version rust version 1.9.0
(the version mentioned in the beginning of this section of the nomicon) and now. Edit: more precisely it seems like 1.19.0
was the last version to have oom()
and heap
like that.
Thanks, for the help. They should've updated the things before releasing it to stable. I'll try modify the finalcode in rust nomicon and see if it works.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.