Search code examples
rustrust-polars

Resolving conflicts w.r.t ambiguous names during imports in rust


New to rust and was trying to develop an application in rust, but ran into an issue.

In my application, i have to use zip module for unzipping a .zip file and need polars for analysis.

my imports looks like something below.

use zip::ZipArchive;
use polars::prelude::*;

.
.

but unfortunately rust-analyzer is complaining with the following message.

unresolved import `zip::ZipArchive`
no `ZipArchive` in `chunked_array::ops::zip

I tried the following too with no luck.

use zip::ZipArchive;
use polars::prelude::*;
use polars::chunked_array::ops::{zip as chunked_zip};
.
.

In my code, i am not explicitly using chunked_array::ops::zip, but would like to understand how to solve in both cases.

  1. Do not explicitly use chunked_array::ops::zip
  2. explicitly use chunked_array::ops::zip

Any help would be much appreciated!!


Solution

  • That's why glob imports are usually frowned upon, especially if the module you import from has popular names like zip.

    You can either import from zip with an absolute path use ::zip::ZipArchive1,

    explicitly import the things you need yourself and remove the use polars::prelude::*;

    Or rename the zip crate for example in your Cargo.toml:

    [dependencies]
    zip_renamed = { package = "zip", … }
    

    1) Thanks Sven Marnach