What is the best way to use a crate dependency of another crate in your crate?


#1

I have a real-life example. I have a discord bot which uses discord-rs crate library to work with the service. The discord-rs crate uses chrono for itself for the dates. In my crate, which uses discord-rs I need to initialize a structure field of discord-rs with a chrono::DateTime type but my crate does not have chrono dependency. What options do I have?


#2

If the discord crate does not export chrono you have to add chrono as a dependency of your own project (and make sure you’re using the same version)


#3

So we have only two options, right? I mean, reexport crate and to use the same dependency crate version in your crate.


#4

Right, you can’t access dependencies of dependencies any other way.


#5

If you are using a dependency of a dependency, then you are directly depending on it so it should be your dependency as well.

If you don’t, tomorrow if the dependency drops it as a dependency, then you will end up with broken code.