Reputation: 469
I am trying to extract bits of code from an embedded rust example that does not compile. A lot of these old embedded examples don't compile because they use nightly and they quickly become broken and neglected.
let mut buffer : [u8; 2048] = [0;2048];
// some code to fill the buffer here
// say we want to split the buffer at position 300
let (request_buffer, response_buffer) = buffer.split_mut_at(300);
This example uses #![no_std]
so there is no standard library to link to and must have compiled at some point so the function split_mut_at must have worked at some point. I am using IntelliJ rust AND Visual Studio Code as the IDE but neither IDE's can point me to the definition of the split_mut_at function. There is a minefield of crates and use statements in the example and there is no clear way to pin-point where some function comes without huge trial and error effort.
btw, split_at_mut can usually be found in std::string::String
Is there a rust command that tells you what crate a function belongs to in your project? It always takes so long to update rust-docs when doing a rust update. Surely that can help!
Upvotes: 0
Views: 442
Reputation: 1394
You're looking for slice::split_at_mut
(note the mut
at the end). It is listed in the nightly docs here and the stable docs here. It is also indeed available with #![no_std]
. It is defined in libcore
here.
As a general rule of thumb when a function x
from core
or std
has a mutable and immutable variant, the function requiring a immutable reference is named x
and the function requiring a mutable reference is named x_mut
.
Upvotes: 1