I'm trying to modularize a program while learning the rust module system. Any idea why this will not compile, why the type/path mismatch?
/main.rs
mod wsl;
use wsl::inv::invoker::Invoker;
use wsl::inv::invocablecategorylist::InvocableCategoryList;
fn main() {
let config = wink::WinkConfig::get_from_cmd_line_args();
let category_list = InvocableCategoryList::get();
if !config.help_msg.is_empty() {
wink::help(
&config.help_msg.to_string(),
config,
category_list.categories,
);
//...
Compilation error:
error[E0308]: mismatched types
--> src/main.rs:46:13
|
46 | category_list.categories,
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `wink::wsl::inv::invocablecategory::InvocableCategory`, found struct `InvocableCategory`
|
= note: expected struct `Vec<wink::wsl::inv::invocablecategory::InvocableCategory>`
found struct `Vec<InvocableCategory>`
/lib.rs
mod wsl;
use crate::wsl::inv::invocablecategory::InvocableCategory;
//...
pub fn help(msg: &str, config: WinkConfig, mut categories: Vec<InvocableCategory>) {
/inv.rs
pub mod invocable;
pub mod invocablecategory;
pub mod invocablecategorylist;
pub mod invoker;
I would prefer to keep these types in wsl::inv but need to keep them in separate files, hence the nested path.
/wsl/inv/invocable.rs defines Invocable struct:
// no mod/use
/wsl/inv/invocablecategory.rs defines InvocableCategory struct
use crate::wsl::inv::invocable::Invocable;
/wsl/inv/invocablecategorylist.rs defines InvocableCategoryList struct
use crate::wsl::get_config_file_path;
use crate::wsl::inv::invocablecategory::InvocableCategory;
//...
pub struct InvocableCategoryList {
/// The categories field contains the list of InvocableCategory.
pub categories: Vec<InvocableCategory>,
}
impl InvocableCategoryList {
/// Return an InvocableCategoryList populated from a hard-coded list of categories
/// plus the contents of $HOME/.wink.json (WSL) or $USERPROFILE/wink.json (Windows).
pub fn get() -> InvocableCategoryList {
let mut category_list = InvocableCategoryList {
categories: Vec::new(),
};
/wsl/inv/invoker.rs: defines Invoker struct
use crate::wsl::inv::invocable::Invocable;
use crate::wsl::wsl_path_or_self;
I can provide the entire source code as a zip if that would help, but it's a bunch of files I don't want to check it in with git until I get it working.