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.
This is not in any way the problem.
The reason for having std be the feature instead of having no_std be the feature is because if a dependency unsets the default features because it does not rely on the std feature and then someone else still does rely on the std feature then everything will still work properly.
If no_std is the feature then if a dependency sets the no_std feature because it does not rely on the std features and then someone else does not set no_std because they do rely on the std features then there will be problems because there won't be any ability for the someone else to unset the no_std feature that was specified by the first dependency.