0

I want to call my Call Struct Data type in other files, but I have this error :

  --> src/router/router.rs:19:34
   |
19 |     xml_files::write_xml_getcapa(wmts_info);
   |                                  ^^^^^^^^^ expected struct `router::router::xml_files::wmts::Wmts`, found struct `router::router::wmts::Wmts`

error: aborting due to previous error; 1 warning emitted

So i understand the Error, and I read other post for solve the problems, but I don't find answer at my question.

My project architecture :

├── mod.rs
├── router.rs
├── wmts_struct.rs
└── xml_files
    └── xml_getcapa.rs

The structure that I want to call is in wmts_struct.rs

pub struct Wmts {
    pub title: String,
    pub service: String,
    pub version: String,
}

impl Wmts {
    pub fn new() -> Wmts {
        Wmts {
            title: String::from("Test"),
            service: String::from("WMS"),
            version: String::from("0.0.1"),
        }
    }
}

in router.rs

#[path = "./wmts_struct.rs"] mod wmts;

#[get("/0.1/WMTSCapabilities.xml")]
pub fn get_capa_request() -> &'static str {
    let wmts_info = wmts::Wmts::new();
    xml_files::write_xml_getcapa(wmts_info);
    "Start to create getCapa file"
}

xml_getcapa.rs

#[path = "./../wmts_struct.rs"]
mod wmts;

pub fn write_xml_getcapa(wmts_info: wmts::Wmts) {
    let mut file = File::create("./GetCapabilities.xml").unwrap();
    let mut writer = EmitterConfig::new()
        .perform_indent(true)
        .create_writer(&mut file);
}

my main.rs

#![feature(proc_macro_hygiene, decl_macro)]

#[macro_use]
extern crate rocket;

mod router;

fn rocket() -> rocket::Rocket {
    rocket::ignite().mount(
        "/",
        routes![router::router::get_capa_request,],
    )
}

fn main() -> () {
    // Start Server
    rocket().launch();
}

Thank you for your Help !

  • 1
    Does this answer your question? [How do I import from a sibling module?](https://stackoverflow.com/questions/30677258/how-do-i-import-from-a-sibling-module) – E_net4 Jul 17 '20 at 10:16
  • 7
    By doing `mod wmts` with a `#[path(...)]` directive, you are actually creating two independent replicas of the same module, and so the types in them won't be compatible. The solution is in the linked question: `mod wmts` on one end and import it on the other end with `use`. `path` directives are usually not needed. – E_net4 Jul 17 '20 at 10:18

0 Answers0