簡體   English   中英

Rust bin 訪問模塊

[英]Rust bin accessing modules

問題

無法從/src/bin/client.rs訪問/src/gameclient/server_connection.rs中的ServerConnection

我沒有任何lib.rsmain.rs所有二進制文件都在/src/bin/

項目結構

在此處輸入圖像描述

Cargo.toml

...
[[bin]]
name = "server"
path = "src/bin/server.rs"

[[bin]]
name = "client"
path = "src/bin/client.rs"
...

/src/gameclient/mod.rs

rust-analyzer 已經在這里抱怨:

文件未包含在模塊樹中

pub mod player_instance;
pub use crate::gameclient::player_instance::PlayerInstance;

pub mod server_connection;
pub use crate::gameclient::server_connection::ServerConnection;

/src/gameclient/server_connection/ServerConnection

...
pub struct ServerConnection {
    pub server_endpoint: url::Url,
}

pub impl ServerConnection {
    pub fn connect(&self) {
...

Pitaj已經給出了正確的答案。

只是為了完整性。

/src/bin/client.rs

在最頂部添加這個讓我擺脫了 lib.rs。

#[path = "../gameclient/mod.rs"]
mod gameclient;

暫無
暫無

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

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