I have a project using workspaces. I have a package, let us call it Client
, that depends on another package in the workspace, let us call that Engine
. Engine
has DataFusion
, an external library as a dependency.
Engine exposes a function that returns a value of type DataFusion
What I am finding out is that if, in Client
package, I call this function in Engine
that returns DataFusion
, I can call methods on the values and everything works fine.
But If I define a function in Client
package, when takes DataFusion
as input, then compilation fails with the error that DataFusion
is not found in scope.
To illustrate. This works fine
// engine.transform is defined in the Engine package
let df = engine.transform();
// I can use the df type alright
df.show().await?;
But this does not compile
fn do_show(df: DataFrame) -> Result<()> {
df.show().await?;
}
Error is cannot find type
DataFrame in this scope
even if I add
use datafusion::dataframe::DataFrame;
at the top, error is
|
8 | use datafusion::dataframe::DataFrame;
| ^^^^^^^^^^ use of undeclared crate or module `datafusion`
Which is correct. Client
does not have DataFrame
as a dependency, it is Engine
that has it.
But the thing I find curious is that, when I did not have to explicitly have to define DataFrame
as a type everything works. The compiler was able to figure out the type of the df
value and it checks that the right methods are called etc.
How is this possible?
And is there a way to have the type available without explicit specifying it as a direct dependency? (I guess not?)