smb_transport/
lib.rs

1#![forbid(unsafe_code)]
2
3use std::time::Duration;
4
5pub mod config;
6pub mod error;
7pub mod iovec;
8pub mod tcp;
9pub mod traits;
10pub mod utils;
11
12pub use config::*;
13pub use error::TransportError;
14pub use iovec::*;
15
16pub use tcp::{SmbTcpMessageHeader, TcpTransport};
17pub use traits::*;
18
19#[cfg(feature = "netbios-transport")]
20pub mod netbios;
21#[cfg(feature = "netbios-transport")]
22pub use netbios::*;
23
24#[cfg(feature = "quic")]
25pub mod quic;
26#[cfg(feature = "quic")]
27pub use quic::*;
28
29#[cfg(feature = "rdma")]
30pub mod rdma;
31#[cfg(feature = "rdma")]
32pub use rdma::*;
33
34/// Creates [`SmbTransport`] out of [`TransportConfig`].
35///
36/// ## Arguments
37/// * `transport` - The transport configuration to make the transport by.
38/// * `timeout` - The timeout duration to use for the transport.
39pub fn make_transport(
40    transport: &TransportConfig,
41    timeout: Duration,
42) -> Result<Box<dyn SmbTransport>, TransportError> {
43    match transport {
44        TransportConfig::Tcp => Ok(Box::new(tcp::TcpTransport::new(timeout))),
45
46        #[cfg(feature = "netbios-transport")]
47        TransportConfig::NetBios => Ok(Box::new(NetBiosTransport::new(timeout))),
48
49        #[cfg(feature = "quic")]
50        TransportConfig::Quic(quic_config) => {
51            Ok(Box::new(quic::QuicTransport::new(quic_config, timeout)?))
52        }
53
54        #[cfg(feature = "rdma")]
55        TransportConfig::Rdma(rdma_config) => {
56            Ok(Box::new(RdmaTransport::new(rdma_config, timeout)))
57        }
58    }
59}
60
61// Force async if QUIC/RDMA are enabled
62#[cfg(all(feature = "is_sync", feature = "quic"))]
63compile_error!(
64    "QUIC transport requires the async feature to be enabled. \
65    Please enable the async feature in your Cargo.toml."
66);
67#[cfg(all(feature = "is_sync", feature = "rdma"))]
68compile_error!(
69    "RDMA transport requires the async feature to be enabled. \
70    Please enable the async feature in your Cargo.toml."
71);