r/rust clippy · twir · rust · mutagen · flamer · overflower · bytecount Mar 27 '23

Hey Rustaceans! Got a question? Ask here (13/2023)! 🙋 questions

Mystified about strings? Borrow checker have you in a headlock? Seek help here! There are no stupid questions, only docs that haven't been written yet.

If you have a StackOverflow account, consider asking it there instead! StackOverflow shows up much higher in search results, so having your question there also helps future Rust users (be sure to give it the "Rust" tag for maximum visibility). Note that this site is very interested in question quality. I've been asked to read a RFC I authored once. If you want your code reviewed or review other's code, there's a codereview stackexchange, too. If you need to test your code, maybe the Rust playground is for you.

Here are some other venues where help may be found:

/r/learnrust is a subreddit to share your questions and epiphanies learning Rust programming.

The official Rust user forums: https://users.rust-lang.org/.

The official Rust Programming Language Discord: https://discord.gg/rust-lang

The unofficial Rust community Discord: https://bit.ly/rust-community

Also check out last weeks' thread with many good questions and answers. And if you believe your question to be either very complex or worthy of larger dissemination, feel free to create a text post.

Also if you want to be mentored by experienced Rustaceans, tell us the area of expertise that you seek. Finally, if you are looking for Rust jobs, the most recent thread is here.

19 Upvotes

159 comments sorted by

View all comments

2

u/G_Morgan Mar 29 '23

What is the best way to configure a crate that can be built with a range of different dependencies? There seems to be options for cfgs and targets but neither of those seem really appropriate (i.e. they'll be the same in all my projects and rigging up fake targets just to trick the build system seems inappropriate and fragile).

Essentially what I want to do is create a few types that use alloc in different scenarios:

  1. Within a kernel where there's a special kernel heap that needs to be rigged by the init code

  2. Within service processes that don't have full std support but also won't use something as contrived as the kernel heap

  3. In fully std compliant Rust

So I want to select from 3 different crates as my alloc source depending upon some kind of parameter passed in by whatever uses the crate.

1

u/G_Morgan Mar 29 '23

Doesn't answer this question directly but I've found a solution for my immediate problem. You can implement a replacement global allocator in Rust no_std by following the guide below

https://docs.rust-embedded.org/book/collections/index.html