Questions tagged [rust-no-std]

38 questions
7
votes
1 answer

Runtime Building: String not found in this scope

A common problem substrate developers might run into: developing a custom pallet to store the mapping into storage with common types, such as String. As an example: #[derive(Encode, Decode, Clone, Default, RuntimeDebug)] pub struct ClusterMetadata…
Nuke
  • 1,032
  • 7
  • 13
5
votes
1 answer

Const array from range

How can I generate a long const array with values taken from a range? Bonus: 1) working with no_std, 2) without using any crates What I would like to do: struct A { a: i32, b: B } enum B { One, Two } const AS: [A; 1024] = [A{a: 1,…
5
votes
2 answers

What do I replace Vec and HashSet with in a no_std environmement?

I'm working on a project that's meant to be compiled to webassembly. So I guess I have to mark the library as no_std. But as it currently relies on Vec, String and HashSet quite a lot this seems to be impossible as I get errors for those…
mottosson
  • 3,283
  • 4
  • 35
  • 73
5
votes
0 answers

Is it possible for a cargo feature to remove a dependency?

I am looking to add the possibility to add the possibility of using my crate without the standard library. Some of the core functionality does depend on floating-point functions, which in no-std mode would need to be provided by libm. The usual way…
user9723177
5
votes
1 answer

How do I most idiomatically write an async IO library in Rust for no_std platforms?

I'm building a library to be used on a no_std platform which allows you to do some common network-related IO, such as making HTTP requests or reading from/writing to Websockets. Now, I would like this library to be a well-behaved citizen so that it…
dflemstr
  • 25,947
  • 5
  • 70
  • 105
4
votes
1 answer

How to write a crate so that std and no_std can coexist in different modules?

I want to write a library, some modules need to support no_std, and others need to support std. I tried to write it with reference to other libraries, but it still seems to be wrong. Cargo.toml: [features] default = ["std"] std =…
hzqelf
  • 857
  • 7
  • 17
4
votes
1 answer

How to manually provide core::panicking::panic* to lld?

I am compiling the Rust code of an rlib to LLVM IR, and then using Clang to compile & link it with a C program. This works until my code contains panics, at which point I get linker errors: ld.lld: error: undefined symbol:…
Cactus
  • 27,075
  • 9
  • 69
  • 149
4
votes
1 answer

Passing an array from C to Rust via FFI with #[!no_std]

All the answers to this question about passing an array from C to Rust use std::slice::from_raw_parts to convert the raw C pointer and some length information into a Rust. In an embedded context (MOS 6502 in my case), there might not be a std…
Cactus
  • 27,075
  • 9
  • 69
  • 149
4
votes
3 answers

How to fill a [u8] array with a repeated u16 value?

I am looking to build an array that will be copied into RAM and sent to an LCD driver. I would like to be able to pass in a color value (color: u16) and use it to populate the array. Note that I am using #![no_std] as this is intended for an…
2
votes
1 answer

Const context: Create array with const generic length from init function

I'm trying to create a container object containing a const array using a const initializer function for each element. For arrays of a fixed size (notated with an integer literal) this is already solved; the twist here is that the length of the array…
Finomnis
  • 18,094
  • 1
  • 20
  • 27
2
votes
2 answers

Why can a no_std crate depend on a crate that uses std?

In the example, hs reexport HashSet from std. But it compiles without error or warning. Why? #![no_std] pub use hs::HashSet; pub fn new() -> HashSet { HashSet::new() } pub fn insert(a: &mut HashSet, v: usize) { …
zxch3n
  • 387
  • 3
  • 9
2
votes
1 answer

verify structure layout at build time

How can I verify the layout of a (repr(C)) structure without running the code? E.g. when I have #[repr(C)] struct Registers { urxd: u32, // 0x00 _rsrvd0: [u32;15], utxd: u32, // 0x40 _rsrvd1: …
ensc
  • 6,704
  • 14
  • 22
2
votes
1 answer

Getting data from a fmt::Arguments without heap allocation

I want to make write! work on my own struct implementing fmt::Write, and I don't have any heap allocation. To do so, I'd need to implement fmt::Write::write_fmt(&mut self, args: fmt::Arguments<'_>) -> fmt::Result However, this means that I need to…
Naeio
  • 1,112
  • 7
  • 21
2
votes
2 answers

How to effectively build a byte array from calculated parts?

I need to build a byte array that represents commands to a device. It may look something like this: let cmds = [ 0x01, // cmd 1 0x02, // cmd 2 0x03, 0xaa, 0xbb, // cmd 3 0x04, // cmd 4 0x05, 0xaa, // cmd 5 ]; Some commands take…
puritii
  • 1,069
  • 1
  • 7
  • 18
1
vote
1 answer

Is there a way to get something like the Command type in no_std?

I was searching and even looking at the core documentation and I didn't see something like the process module or similar, is there a way to achieve this? or it is impossible without the standard library?
FRostri
  • 357
  • 1
  • 5
  • 11
1
2 3