2 ms·
In Rust you can tag a function with arbitrary configuration parameters, it's common to write #[cfg(unix)] but you could equally write #[cfg(linux)] It's jus
by tialaramex 5y ago
In Rust you can tag a function with arbitrary configuration parameters, it's common to write
#[cfg(unix)]
but you could equally write
#[cfg(linux)]
It's just that you're much less likely to need to say this. For example OSStr (borrowed reference to the Operating System specific string type) has #[cfg(unix)] reflecting APIs that make sense for a Unix-style string while #[cfg(windows)] wraps APIs that make sense if your operating system once thought characters are a u16. But the ordinary str and String don't have such APIs, you have to explicitly tell the language "I need this gross non-portable stuff" before you have to start using macros to get to the specific platform dependant elements.
I suspect you could do a similar trick in C++ but it may not be standardised anywhere.
- pornel 5y agoMoreover, Rust is working on portability lints: https://github.com/rust-lang/rfcs/blob/master/text/1868-portability-lint.md https://github.com/rust-lang/rfcs/blob/master/text/1868-port... So that even when you only compile and test your code on Linux, you will get warnings about calling Linux-only functions from maybe-Windows functions.
- comex 5y agoFor some definition of “working on”. The RFC was accepted several years ago, but nobody has stepped forward to actually implement it.