簡體   English   中英

Rust - 在父目錄中使用模塊

[英]Rust - Use module in a parent directory

我的文件結構類似於以下內容:

src/
--clients/
----queue_client/
------mod.rs
--data_evaluator/
----data_evaluator.rs

在 data_evaluator 中,我想使用queue_client模塊,但是當我在 data_evaluator.rs 中執行mod queue_client data_evaluator.rs - 我收到以下錯誤 - File not found for module queue_client 如果我將它移動到data_evaluator文件夾中,它只會找到該模塊。

我的問題是,如何正確使用消費者代碼目錄之外的模塊? 抱歉,如果有一種簡單的方法可以做到這一點,我確實嘗試了很長時間,但找不到方法。

你好像有點糊塗了。 在 Rust 中,構建模塊樹。 您使用mod將模塊注冊為當前模塊的子模塊。 您使用use來使用當前模塊中的模塊。 這篇文章可能會澄清一些事情: http://www.sheshbabu.com/posts/rust-module-system/

除此之外,要使用樹中比當前模塊更高的模塊,您可以使用crate到達模塊樹的根目錄。 所以在你的情況下, crate::clients::queue_client

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM