1

I'd like to import a crate into my library, and then use that crate as if it's a module in my library. If I do this:

extern crate sdl2;
pub use sdl2;

That gives me an error, suggesting I use sdl2::*, but I don't want to drag all the names from the crate into my library, I want them addressed as a sub-module, for example:

my_library::sdl2::init()

I also tried this:

pub extern crate sdl2;

That compiles, but I have no idea what it does. It doesn't seem to make the crate publicly accessible from my library though.

Benjamin Lindley
  • 101,917
  • 9
  • 204
  • 274

2 Answers2

1

You can use renaming in use and extern crate:

extern crate sdl2 as sdl2_;
pub use sdl2_ as sdl2;

I personally found how to do it in stdx crate (which appears to be deprecated/abandoned, though, at least for now).

Vladimir Matveev
  • 120,085
  • 34
  • 287
  • 296
0

Another workaround:

extern crate sdl2;
mod sdl2 {
    pub use ::sdl2::*;
}

Should work -- untested though.

Lukas Kalbertodt
  • 79,749
  • 26
  • 255
  • 305