pub trait Agent<S>:
'static
+ Send
+ Sync{
// Required method
fn new_session(&mut self, socket: &S::Stream) -> impl Session;
}
Expand description
Factory of sessions for the given type of sockets.
An agent implementation is automatically created for types which
implement Session
and Clone
: new sessions are created by
cloning the agent object. This is usually sufficient for the
majority of use cases. In case the information about the
underlying socket (connection source) is needed the Agent
can
be implemented manually.
§Examples
This example shows how to retrieve the connecting process ID on Unix:
use ssh_agent_lib::agent::{Agent, Session};
#[derive(Debug, Default)]
struct AgentSocketInfo;
#[cfg(unix)]
impl Agent<tokio::net::UnixListener> for AgentSocketInfo {
fn new_session(&mut self, socket: &tokio::net::UnixStream) -> impl Session {
let _socket_info = format!(
"unix: addr: {:?} cred: {:?}",
socket.peer_addr().unwrap(),
socket.peer_cred().unwrap()
);
Self
}
}
Required Methods§
Sourcefn new_session(&mut self, socket: &S::Stream) -> impl Session
fn new_session(&mut self, socket: &S::Stream) -> impl Session
Create a Session
object for a given socket
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.