Skip to content

Commit 577d5fb

Browse files
committed
Add doc examples to the agent::ListeningSocket trait
Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
1 parent 1304224 commit 577d5fb

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/agent.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,39 @@ use crate::proto::SignRequest;
3434
use crate::proto::SmartcardKey;
3535

3636
/// Type representing a socket that asynchronously returns a list of streams.
37+
///
38+
/// This trait is implemented for [TCP sockets](TcpListener) on all
39+
/// platforms, Unix sockets on Unix platforms (e.g. Linux, macOS) and
40+
/// Named Pipes on Windows.
41+
///
42+
/// Objects implementing this trait are passed to the [`listen`]
43+
/// function.
44+
///
45+
/// # Examples
46+
///
47+
/// The following example starts listening for connections and
48+
/// processes them with the `MyAgent` struct.
49+
///
50+
/// ```no_run
51+
/// # async fn main_() -> testresult::TestResult {
52+
/// use ssh_agent_lib::agent::{listen, Session};
53+
/// use tokio::net::TcpListener;
54+
///
55+
/// #[derive(Default, Clone)]
56+
/// struct MyAgent;
57+
///
58+
/// impl Session for MyAgent {
59+
/// // implement your agent logic here
60+
/// }
61+
///
62+
/// listen(
63+
/// TcpListener::bind("127.0.0.1:8080").await?,
64+
/// MyAgent::default(),
65+
/// )
66+
/// .await?;
67+
/// # Ok(()) }
68+
/// ```
69+
3770
#[async_trait]
3871
pub trait ListeningSocket {
3972
/// Stream type that represents an accepted socket.

0 commit comments

Comments
 (0)