by sapiogram · 1y ago · 0 comments
You can with Rust features. It allows a library to conditionally compile certain parts of the code, and users of the library can decide which features to enable.
If a library only uses stdlib in code gated by #[feature(std)], users can disable that flag, and use the library in no_std contexts.
But maybe i should first learn rust before asking.
Consider these common libraries you might use in either a `std` project (PC application, web microservice) or `no_std` project (embedded microcontroller firmware, bootloader, Linux kernel module, blockchain smart contract):
- data encoding (https://crates.io/crates/base64 for instance),
- hashing (SHA2 https://github.com/RustCrypto/hashes/tree/master/sha2),
- data structures (https://github.com/Lokathor/tinyvec)
- time/date manipulation (https://docs.rs/chrono/latest/chrono/)
https://docs.rs/jiff/latest/jiff/tz/index.html#core-only-env...
I think with sloppy/complex code it could start to resemble #ifdef PLATFORM complexity if you do a lot inline, but cargo workspaces are a good way to reduce the blast radius.