Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to group imports in Rust with conditional compilation?

I am looking to group all my imports with conditional compilation.

I know that the #[cfg(target_os = "windows")] attribute organises the import, but it only works for one import.

How can I import multiple packages with one conditional compilation attribute?

I am looking for something like:

#[cfg(target_os = "windows")]
{
    use windows_lib1;
    use windows_lib2;
}

#[cfg(target_os = "linux")]
{
    use linux_lib1;
    use linux_lib2;
}
like image 284
Akiner Alkan Avatar asked Sep 30 '19 12:09

Akiner Alkan


1 Answers

You can group use imports this way:

#[cfg(target_os = "windows")]
use {
    windows_lib1,
    windows_lib2,
};
like image 77
Denys Séguret Avatar answered Dec 02 '22 22:12

Denys Séguret