Skip to content

Commit c55b189

Browse files
committed
Add example to agent::listen
Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
1 parent 19fce9c commit c55b189

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/agent.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,31 @@ where
261261

262262
/// Listen for connections on a given socket and use session factory
263263
/// to create new session for each accepted socket.
264+
///
265+
/// # Examples
266+
///
267+
/// The following example starts listening for connections and
268+
/// processes them with the `MyAgent` struct.
269+
///
270+
/// ```no_run
271+
/// # async fn main_() -> testresult::TestResult {
272+
/// use ssh_agent_lib::agent::{listen, Session};
273+
/// use tokio::net::TcpListener;
274+
///
275+
/// #[derive(Default, Clone)]
276+
/// struct MyAgent;
277+
///
278+
/// impl Session for MyAgent {
279+
/// // implement your agent logic here
280+
/// }
281+
///
282+
/// listen(
283+
/// TcpListener::bind("127.0.0.1:8080").await?,
284+
/// MyAgent::default(),
285+
/// )
286+
/// .await?;
287+
/// # Ok(()) }
288+
/// ```
264289
pub async fn listen<S>(mut socket: S, mut sf: impl Agent<S>) -> Result<(), AgentError>
265290
where
266291
S: ListeningSocket + fmt::Debug + Send,

0 commit comments

Comments
 (0)