How do you have a default target [[cfg] in rust for "everything else"?

The # [cfg] helper is rather obscure and not particularly well documented, but when I go through librustc I have a pretty reasonable list of all available configuration goals (target_os, target_family, target_arch, target_endian, target_word_size, windows, unix), and of course you can use not (..) to indicate combinations.

However, I cannot figure out how to implement the default implementation.

Is there a way to do this with cfg?

#[cfg(???)] <--- What goes here?
fn thing {
  panic!("Not implemented! Please file a bug at http://... to request support for your platform")
}

#[cfg(target_os = "mac_os"]
fn thing() {
  // mac impl 
}

#[cfg(target_os = "windows"]] 
fn thing() {
  // windows impl
}

I see that in stdlib there are several:

#[cfg(not(any(target_os = "macos", target_os = "ios", windows)]

This is due to tedious copy and paste. Is this the only way?

(Are panics wrong? Don't do this? This is for the build.rs script where you should and should panic in order to raise the error to the load)

+4
2

. ?

RFC , , . :

#[cfg(other)]
fn thing {

cfg, , thing , mac_os windows .

, :

#[cfg(other)]
fn thing_some_other {
  panic!("Not implemented! Please file a bug at http://... to request support for your platform")
}

#[cfg(target_os = "mac_os"]
fn thing() {
  // mac impl 
}

#[cfg(target_os = "windows"]] 
fn thing() {
  // windows impl
}

, , C:

#ifdef WINDOWS
    // ...
#elif LINUX
     // ...
#else
     // ...
#endif
+3

; cfg(not(any(…, …))) - .

"- ", script , (, unimplemented!(), , ).

, , , , , , , ( , ), -, , cfg , , :

#[cfg(not(any(target_os = "windows", target_os = "mac")))]
fn thing() {
    sorry! (this function is unimplemented for this platform, please report a bug at X)
}

Windows Mac, Linux, sorry ( , tokenise, , ). , (, sorry = "message" let), .

+2

All Articles