@@ -448,6 +448,12 @@ where
448
448
}
449
449
}
450
450
451
+ #[ cfg( unix) ]
452
+ type PlatformSpecificListener = tokio:: net:: UnixListener ;
453
+
454
+ #[ cfg( windows) ]
455
+ type PlatformSpecificListener = NamedPipeListener ;
456
+
451
457
/// Bind to a service binding listener.
452
458
///
453
459
/// # Examples
@@ -482,10 +488,9 @@ where
482
488
/// Ok(())
483
489
/// }
484
490
/// ```
485
- #[ cfg( unix) ]
486
491
pub async fn bind < A > ( listener : service_binding:: Listener , agent : A ) -> Result < ( ) , AgentError >
487
492
where
488
- A : Agent < tokio :: net :: UnixListener > + Agent < tokio:: net:: TcpListener > ,
493
+ A : Agent < PlatformSpecificListener > + Agent < tokio:: net:: TcpListener > ,
489
494
{
490
495
match listener {
491
496
#[ cfg( unix) ]
@@ -495,57 +500,13 @@ where
495
500
service_binding:: Listener :: Tcp ( listener) => {
496
501
listen ( TcpListener :: from_std ( listener) ?, agent) . await
497
502
}
498
- _ => Err ( AgentError :: IO ( std:: io:: Error :: other (
499
- "Unsupported type of a listener." ,
500
- ) ) ) ,
501
- }
502
- }
503
-
504
- /// Bind to a service binding listener.
505
- ///
506
- /// # Examples
507
- ///
508
- /// The following example uses `clap` to parse the host socket data
509
- /// thus allowing the user to choose at runtime whether they want to
510
- /// use TCP sockets, Unix domain sockets (including systemd socket
511
- /// activation) or Named Pipes (under Windows).
512
- ///
513
- /// ```no_run
514
- /// use clap::Parser;
515
- /// use service_binding::Binding;
516
- /// use ssh_agent_lib::agent::{bind, Session};
517
- ///
518
- /// #[derive(Debug, Parser)]
519
- /// struct Args {
520
- /// #[clap(long, short = 'H', default_value = "unix:///tmp/ssh.sock")]
521
- /// host: Binding,
522
- /// }
523
- ///
524
- /// #[derive(Default, Clone)]
525
- /// struct MyAgent;
526
- ///
527
- /// impl Session for MyAgent {}
528
- ///
529
- /// #[tokio::main]
530
- /// async fn main() -> Result<(), Box<dyn std::error::Error>> {
531
- /// let args = Args::parse();
532
- ///
533
- /// bind(args.host.try_into()?, MyAgent::default()).await?;
534
- ///
535
- /// Ok(())
536
- /// }
537
- /// ```
538
- #[ cfg( windows) ]
539
- pub async fn bind < A > ( listener : service_binding:: Listener , agent : A ) -> Result < ( ) , AgentError >
540
- where
541
- A : Agent < NamedPipeListener > + Agent < tokio:: net:: TcpListener > ,
542
- {
543
- match listener {
544
- service_binding:: Listener :: Tcp ( listener) => {
545
- listen ( TcpListener :: from_std ( listener) ?, agent) . await
546
- }
503
+ #[ cfg( windows) ]
547
504
service_binding:: Listener :: NamedPipe ( pipe) => {
548
505
listen ( NamedPipeListener :: bind ( pipe) ?, agent) . await
549
506
}
507
+ #[ allow( unreachable_patterns) ]
508
+ _ => Err ( AgentError :: IO ( std:: io:: Error :: other (
509
+ "Unsupported type of a listener." ,
510
+ ) ) ) ,
550
511
}
551
512
}
0 commit comments