Import not found when using latest `master`

Hello Folks,

Disclaimer: I’m fairly new to Rust, so it could be that I’m doing something completely obvious or silly, therefore, I ask you exercise patience if this seems like a glaring/obvious mistake. The truth is, I wouldn’t be posting here if I would have been able to figure this out; I hope to learn something new :slight_smile:

I have created a fresh Rust project (latest stable rust), and to separate things, I have used the workspace feature, the way I think is correct. (I’ll show the details of the project structure below) but first I’d like to point out the error in case this is fairly simple:

In my “main/root” Cargo.toml, I’ve added

[dependencies.iced]
git = ... (url of the iced repo)
rev = ... latest rev on master

(note: I tried the rev linked in the documentation and even none at all, it’s the same).

Now, this seems to work fine except I cannot find many of the usual imports, like “iced::Sandbox” for example.

So in main.rs I get a red import.

Now, if I change the above to just

[dependencies]
iced = "0.12.1"

It works fine. (I want to use the latest though…)

Am I missing something here?

Details about the project structure

Because I wanted to separate most of the logic, I created a lib project inside this one.

The structure is simple, let’s say the app is called… app in the name of originality:

/app
/app/applib
/app/applib/src
/app/applib/src/lib.rs
/app/applib/Cargo.toml # 1
/app/src
/app/src/main.rs
/app/Cargo.toml #2

Cargo.toml number 1 (the lib one)
looks like:

[package]
name = "applib"
# version, edition, etc... all standard (omitted for brevity)

#dep versions omitted here for brevity as well...
[dependencies]
serde = ...
serde_yaml = ...
git2 = ...

In the Cargo.toml number 2, that is the “main crate”, I have:

workspace = { members = ["applib"] }
[package]
name = "app"
# version, edition, etc... 

[[bin]]
name = "myapp"
path = "src/main.rs"

[dependencies]
applib = { path = "applib" }

[dependencies.iced]
git = ... # path to iced github
rev = ... # HEAD of master atm, but tried others.

Now when I do this, the app was working fine (that is, all the code in main.rs is able to use the applib crate and access its public code.
But the Iced dependency, is for the app not the lib, since the lib contains no UI code.

However, as it is, it just doesn’t work.

In main.rs, I do for e.g.:

use iced::{Application} # this line is red, import cannot be found.

fn main() {
    println!("hello");
}

#[derive(Default, Debug, Clone)]
enum MyApp {
    #[default]
    Loading,
    SomeState,
}

impl Application for MyApp { ## This line is red because `Application` is not found.

}

Now, if I change the cargo.toml to use:

[dependencies]
applib = { path = "applib" }
iced = "0.12.1"

#[dependencies.iced]
#git = ... # path to iced github
#rev = ... # HEAD of master atm, but tried others.

Then the import works fine!

What am I missing?

Thank you for your help!

Could you share the Error that the rust analyzer is giving you?

Absolutely.

Using Sandbox as an example, there are two errors:

(btw, I’m using RustRover, if it matters)

Unresolved import: `iced::Sandbox` [E0432]:1
Cannot find trait `Sandbox` in this scope [E0405]:21

I suppose the numbers at the end are the line numbers where the error happens.

I don’t see any other error.

The rev I’m using is:

72b975ec82660b39f27b6cb015b763caf20e6483

EDIT: I tried doing cargo build from a terminal emulator.

The Rust Error underlines the Sandbox in the use statement with:

use iced::{Element, Sandbox};
                    ^^^^^^^ no `Sandbox` in the root

Is this what you were after?

Last Update:

I was doing all this on a macOS machine. Since I don’t like them much (work machine) I decided to try on a Linux box.

I created a fresh project, then added a crate (type library) and it looks exactly like the code I’ve manually created on the work machine, the lib.rs even comes with a simple “add(x,y)” function that works when called from the simple main():

fn main() {
    println!("Hello, world!");
    applib::add(1,2);
}

But adding an enum, then impl Sandbox for MyEnum fails the same way when using the latest master commit, and not when using iced 0.12.1 directly.

Sandbox has been removed in master:

1 Like

Ahhh well that explains it then! Apologies for the noise.

I was following “the book” and it suggested to use certain commit, but I figured using a more recent one was better; I guess I was very wrong.

Thank you very much, I’ll take a look at the new API.