1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! Backend module for different transport implementations.
//!
//! This module provides various backends for session communication,
//! including PTY for local processes and SSH for remote connections.
mod pty;
// Export AsyncPty and PtyHandle for Unix platforms
#[cfg(unix)]
pub use pty::{AsyncPty, PtyHandle};
pub use pty::{EnvMode, PtyConfig, PtySpawner, PtyTransport};
// Export WindowsAsyncPty and WindowsPtyHandle for Windows platforms
#[cfg(windows)]
pub use pty::{WindowsAsyncPty, WindowsPtyHandle};
// SSH backend is conditionally compiled
#[cfg(feature = "ssh")]
pub mod ssh;
/// Trait for session backends.
pub trait Backend {
/// The transport type produced by this backend.
type Transport;
/// Check if the backend is available.
fn is_available(&self) -> bool;
/// Get the backend name.
fn name(&self) -> &'static str;
}
/// Available backend types.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BackendType {
/// Local PTY backend.
Pty,
/// SSH backend for remote connections.
Ssh,
/// Mock backend for testing.
Mock,
}
impl BackendType {
/// Check if this backend is available.
#[must_use]
pub const fn is_available(self) -> bool {
match self {
Self::Pty => cfg!(unix) || cfg!(windows),
Self::Ssh => cfg!(feature = "ssh"),
Self::Mock => cfg!(feature = "mock"),
}
}
/// Get the backend name.
#[must_use]
pub const fn name(self) -> &'static str {
match self {
Self::Pty => "pty",
Self::Ssh => "ssh",
Self::Mock => "mock",
}
}
}