66//!
77//! - [x] [mDNS-SD (HTTP)](https://www.w3.org/TR/wot-discovery/#introduction-dns-sd-sec)
88
9+ use std:: marker:: PhantomData ;
10+
911use futures_core:: Stream ;
1012use futures_util:: StreamExt ;
1113use mdns_sd:: { ServiceDaemon , ServiceEvent , ServiceInfo } ;
1214use tracing:: debug;
1315
14- use wot_td:: thing:: Thing ;
16+ use wot_td:: {
17+ extend:: { Extend , ExtendablePiece , ExtendableThing } ,
18+ hlist:: Nil ,
19+ thing:: Thing ,
20+ } ;
1521
1622/// The error type for Discovery operation
1723#[ derive( thiserror:: Error , Debug ) ]
@@ -31,12 +37,15 @@ pub type Result<T> = std::result::Result<T, Error>;
3137const WELL_KNOWN : & str = "/.well-known/wot" ;
3238
3339/// Discover [Web Of Things](https://www.w3.org/WoT/) via a supported Introduction Mechanism.
34- pub struct Discoverer {
40+ pub struct Discoverer < Other : ExtendableThing + ExtendablePiece = Nil > {
3541 mdns : ServiceDaemon ,
3642 service_type : String ,
43+ _other : PhantomData < Other > ,
3744}
3845
39- async fn get_thing ( info : ServiceInfo ) -> Result < Thing > {
46+ async fn get_thing < Other : ExtendableThing + ExtendablePiece > (
47+ info : ServiceInfo ,
48+ ) -> Result < Thing < Other > > {
4049 let host = info. get_addresses ( ) . iter ( ) . next ( ) . ok_or ( Error :: NoAddress ) ?;
4150 let port = info. get_port ( ) ;
4251 let props = info. get_properties ( ) ;
@@ -60,11 +69,36 @@ impl Discoverer {
6069 pub fn new ( ) -> Result < Self > {
6170 let mdns = ServiceDaemon :: new ( ) ?;
6271 let service_type = "_wot._tcp.local." . to_owned ( ) ;
63- Ok ( Self { mdns, service_type } )
72+ Ok ( Self {
73+ mdns,
74+ service_type,
75+ _other : PhantomData ,
76+ } )
77+ }
78+ }
79+
80+ impl < Other : ExtendableThing + ExtendablePiece > Discoverer < Other > {
81+ /// Extend the [Discoverer] with a [ExtendableThing]
82+ pub fn ext < T > ( self ) -> Discoverer < Other :: Target >
83+ where
84+ Other : Extend < T > ,
85+ Other :: Target : ExtendableThing + ExtendablePiece ,
86+ {
87+ let Discoverer {
88+ mdns,
89+ service_type,
90+ _other,
91+ } = self ;
92+
93+ Discoverer {
94+ mdns,
95+ service_type,
96+ _other : PhantomData ,
97+ }
6498 }
6599
66100 /// Returns an Stream of discovered things
67- pub fn stream ( & self ) -> Result < impl Stream < Item = Result < Thing > > > {
101+ pub fn stream ( & self ) -> Result < impl Stream < Item = Result < Thing < Other > > > > {
68102 let receiver = self . mdns . browse ( & self . service_type ) ?;
69103
70104 let s = receiver. into_stream ( ) . filter_map ( |v| async move {
0 commit comments