rustrust-crates

What's the polite way for my library to return types from another crate?


I'm making a toy numerical crate, and some of my return types are complex numbers. I'm relying on num-complex under the hood, but my return types are also complex numbers. I considered simply returning tuples of f64 values, but that doesn't feel right.

If you were using a crate, how would you want to see this done? I hate to force anyone to include a dependency they don't want—even one as well-maintained as num-complex. Is it alright to pub use the complex type, or is there a more acceptable way?

Thanks for your time!


pub use num_complex::Complex64;
// and return a Complex64 value...

or

use num_complex::Complex64;
// and return a tuple of `f64`?

Solution

  • This is called a "public dependency".

    The proper way to handle this will be, in the future when RFC 3516 is stabilized, to mark the dependency as public = true in Cargo.toml.

    In the meantime (and maybe after that too), you can (and should) re-export that dependency from your library:

    pub extern crate num_complex;
    

    Then, users can refer to it as your_library::num_complex.