How to use pub struct inside a private mod?

โš“ Rust    ๐Ÿ“… 2026-01-27    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 1      

surdeus

When testing tokio-quiche by building an example, I create a trait, struct

trait Ping {
  fn listen<H: DriverHooks>(self, fn(H3Controller<H>) -> ());
} 

struct Server {
  address: tokionet::net::UdpSocket,
}

When implementing the trait for the struct, I encounter a problem where a parameterized type inside a returned value actually is located inside a private module. Therefore, while attempting to fix cannot find trait ... in this scope error, I can not simply use tokio_quiche::http3::driver::server::DriverHooks as import statement. Rust will complains module server is private, but without use statement, Rust complains can't find trait in this scope. How to fix this? Thanks.

The code snippet is as below

impl Ping for Server {
  fn listen<H: DriverHooks>(self, f: fn(H3Controller<H>) -> ()) {
    ... // the code to create accept_stream is the same as the example provided by tokio_quiche
    while let Some(conn) = accept_stream.next().await {
        let (driver, controller) = ServerH3Driver::new(Http3Settings::default()); // controller is H3Cotroller<ServerHooks> type
        conn?.start(driver);
        tokio::spawn(f(controller)); 
    }
  }
}

Example provided by tokio-quiche: quiche/tokio-quiche at master ยท cloudflare/quiche ยท GitHub

4 posts - 3 participants

Read full topic

๐Ÿท๏ธ Rust_feed