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
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!