(self, provider: P) -> Services {
+ Services {
+ chat: provider,
+ }
+ }
+}
+
+impl Services {
+ /// Provide every protocol given on `conn`: the peer's calls to them come here.
+ /// The protocols left [`Absent`] aren't provided.
+ pub fn provide_on(self, conn: &mut Connection) -> Result<(), RuntimeError> {
+ ProvideConformanceChat::provide(self.chat, conn)?;
+ Ok(())
+ }
+}
+
+/// What the dialling side provides: one field per protocol. Every field is a
+/// protocol's implementation, or [`Absent`] to leave the protocol out;
+/// `ClientServices::new()` has them all absent, and `with_` provides one.
pub struct ClientServices {
pub events: Events,
}
-impl ClientServices {
- /// Provide every protocol on `conn`: the peer's calls to them come here.
- pub fn provide_on(self, conn: &mut Connection) {
- crate::conformance::EventsDispatcher(self.events).provide_on(conn);
+impl ClientServices {
+ /// Nothing provided yet.
+ pub fn new() -> Self {
+ ClientServices {
+ events: Absent,
+ }
+ }
+}
+
+impl Default for ClientServices {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+impl ClientServices {
+ /// Provide `conformance::Events` with `provider`, in place of what was there.
+ pub fn with_events(self, provider: P) -> ClientServices {
+ ClientServices {
+ events: provider,
+ }
+ }
+}
+
+impl ClientServices {
+ /// Provide every protocol given on `conn`: the peer's calls to them come here.
+ /// The protocols left [`Absent`] aren't provided.
+ pub fn provide_on(self, conn: &mut Connection) -> Result<(), RuntimeError> {
+ ProvideConformanceEvents::provide(self.events, conn)?;
+ Ok(())
}
}
@@ -55,22 +151,22 @@ impl ClientServices {
/// every protocol in `services` on it. The connection comes back not yet
/// served, for a server that calls the client first, or serves one call at
/// a time.
-pub fn accept(transport: T, services: Services) -> Result, RuntimeError> {
+pub fn accept(transport: T, services: Services) -> Result, RuntimeError> {
let mut conn = comline_runtime::connection::Connection::accept(transport, Format::default(), CONNECTION_IR_HASH)?;
- services.provide_on(&mut conn);
+ services.provide_on(&mut conn)?;
Ok(conn)
}
/// [`accept`], then serve every call until the peer leaves.
-pub fn serve(transport: T, services: Services) -> Result<(), RuntimeError> {
+pub fn serve(transport: T, services: Services) -> Result<(), RuntimeError> {
accept(transport, services)?.serve()
}
/// Dial over `transport`: run the handshake, then provide every protocol in
/// `services`, which the server calls. Call the server's protocols through
/// their senders.
-pub fn connect(transport: T, services: ClientServices) -> Result, RuntimeError> {
+pub fn connect(transport: T, services: ClientServices) -> Result, RuntimeError> {
let mut conn = comline_runtime::connection::Connection::connect(transport, Format::default(), CONNECTION_IR_HASH)?;
- services.provide_on(&mut conn);
+ services.provide_on(&mut conn)?;
Ok(conn)
}
diff --git a/codegen/tests/golden/connections_async/rust/conformance.rs b/codegen/tests/golden/connections_async/rust/conformance.rs
index 11b4f9b..76fa733 100644
--- a/codegen/tests/golden/connections_async/rust/conformance.rs
+++ b/codegen/tests/golden/connections_async/rust/conformance.rs
@@ -1,5 +1,5 @@
// This file uses `comline_runtime`'s async driver - enable its feature in your Cargo.toml:
-// comline-runtime = { git = "https://github.com/ComlineProject/runtime", rev = "3b9cc9dc53a83fb2830d91b267bd5f477f0a1e51", features = ["async"] }
+// comline-runtime = { git = "https://github.com/ComlineProject/runtime", rev = "e7362217e95f8d22bbce181746562054974e659a", features = ["async"] }
// Generated by Comline
// For Rust 1.85.0 or later; verified up to 1.99.
use serde::{Deserialize, Serialize};
@@ -74,7 +74,14 @@ impl ChatAsyncDispatcher {
/// Provide this protocol on `conn`: the peer's calls to it come here.
/// Open `conn` with `AsyncConnection::accept(transport, format, CONNECTION_IR_HASH)`, or let the package's `serve` / `connect` do it.
- pub fn provide_on(self, conn: &mut AsyncConnection)
+ ///
+ /// Fails with `RuntimeError::Unavailable` when the connection ran a `comline@2`
+ /// handshake that didn't accept this protocol: the Hello didn't list it, or the
+ /// peer refused it. A connection opened without one accepts it.
+ pub fn provide_on(
+ self,
+ conn: &mut AsyncConnection,
+ ) -> Result<(), RuntimeError>
where
T: AsyncTransport,
W: WireFormat + Send + Sync + 'static,
@@ -176,7 +183,14 @@ impl EventsAsyncDispatcher {
/// Provide this protocol on `conn`: the peer's calls to it come here.
/// Open `conn` with `AsyncConnection::connect(transport, format, CONNECTION_IR_HASH)`, or let the package's `serve` / `connect` do it.
- pub fn provide_on(self, conn: &mut AsyncConnection)
+ ///
+ /// Fails with `RuntimeError::Unavailable` when the connection ran a `comline@2`
+ /// handshake that didn't accept this protocol: the Hello didn't list it, or the
+ /// peer refused it. A connection opened without one accepts it.
+ pub fn provide_on(
+ self,
+ conn: &mut AsyncConnection,
+ ) -> Result<(), RuntimeError>
where
T: AsyncTransport,
W: WireFormat + Send + Sync + 'static,
diff --git a/codegen/tests/golden/connections_async/rust/connection.rs b/codegen/tests/golden/connections_async/rust/connection.rs
index f130cbd..d987c56 100644
--- a/codegen/tests/golden/connections_async/rust/connection.rs
+++ b/codegen/tests/golden/connections_async/rust/connection.rs
@@ -6,6 +6,7 @@
//! - Implement the trait of each protocol the client provides: `conformance::Events`.
//! - Serve with [`serve`]`(transport, Services { chat: .. }).await`, which runs until the peer leaves. [`accept`] hands the connection back first, not yet running: take its `handle()` to call the client, then `run().await` it.
//! - Dial with [`connect`]`(transport, ClientServices { events: .. }).await`, then `run().await` the connection it returns.
+//! - To provide only some of a side's protocols, start from `Services::new().with_chat(..)` or `ClientServices::new().with_events(..)` and add each with its `with_` method, or write [`Absent`] in the fields left out. The connection then has a dispatcher for those only.
//! - Call the server from the dialling side: `ChatAsyncSender::new(&conn.handle()).send(..).await`.
//! - Call the client from the accepting side, on the connection [`accept`] returns or the peer a handler is given: `EventsAsyncSender::new(&conn.handle()).shown(..).await`.
//!
@@ -25,29 +26,124 @@ pub const CONNECTION_IR_HASH: u64 = 0xb97e34b203ec1425;
/// return, written `Connection`: [`Format`] over the default framing.
pub type Connection = comline_runtime::connection::AsyncConnection;
-/// What the accepting side provides: one field per protocol, so leaving one out
-/// doesn't compile.
+/// A protocol left out of [`Services`] or [`ClientServices`]: it isn't provided,
+/// and the connection has no dispatcher for it.
+#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
+pub struct Absent;
+
+/// What provides `conformance::Chat` in [`Services`] or [`ClientServices`]: its trait's implementor, or [`Absent`].
+#[doc(hidden)]
+pub trait ProvideConformanceChat {
+ fn provide(self, conn: &mut Connection) -> Result<(), RuntimeError>;
+}
+
+impl ProvideConformanceChat for Absent {
+ fn provide(self, _conn: &mut Connection) -> Result<(), RuntimeError> {
+ Ok(())
+ }
+}
+
+impl ProvideConformanceChat for P {
+ fn provide(self, conn: &mut Connection) -> Result<(), RuntimeError> {
+ crate::conformance::ChatAsyncDispatcher(self).provide_on(conn)
+ }
+}
+
+/// What provides `conformance::Events` in [`Services`] or [`ClientServices`]: its trait's implementor, or [`Absent`].
+#[doc(hidden)]
+pub trait ProvideConformanceEvents {
+ fn provide(self, conn: &mut Connection) -> Result<(), RuntimeError>;
+}
+
+impl ProvideConformanceEvents for Absent {
+ fn provide(self, _conn: &mut Connection) -> Result<(), RuntimeError> {
+ Ok(())
+ }
+}
+
+impl ProvideConformanceEvents for P {
+ fn provide(self, conn: &mut Connection) -> Result<(), RuntimeError> {
+ crate::conformance::EventsAsyncDispatcher(self).provide_on(conn)
+ }
+}
+
+/// What the accepting side provides: one field per protocol. Every field is a
+/// protocol's implementation, or [`Absent`] to leave the protocol out;
+/// `Services::new()` has them all absent, and `with_` provides one.
pub struct Services {
pub chat: Chat,
}
-impl Services {
- /// Provide every protocol on `conn`: the peer's calls to them come here.
- pub fn provide_on(self, conn: &mut Connection) {
- crate::conformance::ChatAsyncDispatcher(self.chat).provide_on(conn);
+impl Services {
+ /// Nothing provided yet.
+ pub fn new() -> Self {
+ Services {
+ chat: Absent,
+ }
}
}
-/// What the dialling side provides: one field per protocol, so leaving one out
-/// doesn't compile.
+impl Default for Services {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+impl Services {
+ /// Provide `conformance::Chat` with `provider`, in place of what was there.
+ pub fn with_chat(self, provider: P) -> Services {
+ Services {
+ chat: provider,
+ }
+ }
+}
+
+impl Services {
+ /// Provide every protocol given on `conn`: the peer's calls to them come here.
+ /// The protocols left [`Absent`] aren't provided.
+ pub fn provide_on(self, conn: &mut Connection) -> Result<(), RuntimeError> {
+ ProvideConformanceChat::provide(self.chat, conn)?;
+ Ok(())
+ }
+}
+
+/// What the dialling side provides: one field per protocol. Every field is a
+/// protocol's implementation, or [`Absent`] to leave the protocol out;
+/// `ClientServices::new()` has them all absent, and `with_` provides one.
pub struct ClientServices {
pub events: Events,
}
-impl ClientServices {
- /// Provide every protocol on `conn`: the peer's calls to them come here.
- pub fn provide_on(self, conn: &mut Connection) {
- crate::conformance::EventsAsyncDispatcher(self.events).provide_on(conn);
+impl ClientServices {
+ /// Nothing provided yet.
+ pub fn new() -> Self {
+ ClientServices {
+ events: Absent,
+ }
+ }
+}
+
+impl Default for ClientServices {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+impl ClientServices {
+ /// Provide `conformance::Events` with `provider`, in place of what was there.
+ pub fn with_events(self, provider: P) -> ClientServices {
+ ClientServices {
+ events: provider,
+ }
+ }
+}
+
+impl ClientServices {
+ /// Provide every protocol given on `conn`: the peer's calls to them come here.
+ /// The protocols left [`Absent`] aren't provided.
+ pub fn provide_on(self, conn: &mut Connection) -> Result<(), RuntimeError> {
+ ProvideConformanceEvents::provide(self.events, conn)?;
+ Ok(())
}
}
@@ -55,22 +151,22 @@ impl ClientServices {
/// every protocol in `services` on it. The connection comes back not yet
/// running, so the caller can take a `handle()` to call the client with
/// before it runs.
-pub async fn accept(transport: T, services: Services) -> Result, RuntimeError> {
+pub async fn accept(transport: T, services: Services) -> Result, RuntimeError> {
let mut conn = comline_runtime::connection::AsyncConnection::accept(transport, Format::default(), CONNECTION_IR_HASH).await?;
- services.provide_on(&mut conn);
+ services.provide_on(&mut conn)?;
Ok(conn)
}
/// [`accept`], then serve every call until the peer leaves.
-pub async fn serve(transport: T, services: Services) -> Result<(), RuntimeError> {
+pub async fn serve(transport: T, services: Services) -> Result<(), RuntimeError> {
accept(transport, services).await?.run().await
}
/// Dial over `transport`: run the handshake, then provide every protocol in
/// `services`, which the server calls. Call the server's protocols through
/// their senders.
-pub async fn connect(transport: T, services: ClientServices) -> Result, RuntimeError> {
+pub async fn connect(transport: T, services: ClientServices) -> Result, RuntimeError> {
let mut conn = comline_runtime::connection::AsyncConnection::connect(transport, Format::default(), CONNECTION_IR_HASH).await?;
- services.provide_on(&mut conn);
+ services.provide_on(&mut conn)?;
Ok(conn)
}
diff --git a/codegen/tests/golden/connections_default/rust/conformance.rs b/codegen/tests/golden/connections_default/rust/conformance.rs
index a6aa6f7..e85a212 100644
--- a/codegen/tests/golden/connections_default/rust/conformance.rs
+++ b/codegen/tests/golden/connections_default/rust/conformance.rs
@@ -96,10 +96,15 @@ impl ChatDispatcher {
/// Provide this protocol on `conn`: the peer's calls to it come here.
/// Open `conn` with the package's `accept` / `serve` / `connect`, which run `comline@2` with this package's facts.
+ ///
+ /// Fails with `RuntimeError::Unavailable` when the connection ran a `comline@2`
+ /// handshake that didn't accept this protocol: the Hello didn't list it, or the
+ /// peer refused it. A connection opened without one accepts it.
pub fn provide_on(
self,
conn: &mut Connection,
- ) where
+ ) -> Result<(), RuntimeError>
+ where
S: 'static,
{
conn.provide(Self::PROTOCOL, self)
@@ -220,10 +225,15 @@ impl EventsDispatcher {
/// Provide this protocol on `conn`: the peer's calls to it come here.
/// Open `conn` with the package's `accept` / `serve` / `connect`, which run `comline@2` with this package's facts.
+ ///
+ /// Fails with `RuntimeError::Unavailable` when the connection ran a `comline@2`
+ /// handshake that didn't accept this protocol: the Hello didn't list it, or the
+ /// peer refused it. A connection opened without one accepts it.
pub fn provide_on(
self,
conn: &mut Connection,
- ) where
+ ) -> Result<(), RuntimeError>
+ where
S: 'static,
{
conn.provide(Self::PROTOCOL, self)
diff --git a/codegen/tests/golden/connections_default/rust/connection.rs b/codegen/tests/golden/connections_default/rust/connection.rs
index 0550366..b428ba7 100644
--- a/codegen/tests/golden/connections_default/rust/connection.rs
+++ b/codegen/tests/golden/connections_default/rust/connection.rs
@@ -6,13 +6,14 @@
//! - Implement the trait of each protocol the client provides: `conformance::Events`.
//! - Serve with [`serve`]`(transport, Services { chat: .. })`, which serves every call until the peer leaves. [`accept`] hands the connection back first, for a server that calls the client or serves one call at a time.
//! - Dial with [`connect`]`(transport, ClientServices { events: .. })`.
+//! - To provide only some of a side's protocols, start from `Services::new().with_chat(..)` or `ClientServices::new().with_events(..)` and add each with its `with_` method, or write [`Absent`] in the fields left out. The `comline@2` Hello then lists what is provided and every protocol of the other side this end calls, and a protocol it doesn't list isn't on the connection.
//! - Call the server from the dialling side: `ChatSender::new(&mut conn).send(..)`.
//! - Call the client from the accepting side, on the connection [`accept`] returns or the peer a handler is given: `EventsSender::new(&mut conn).shown(..)`.
//!
//! [`Connection`](Connection) names the connection over a transport `T`, written `Connection`; [`Format`] is the package's wire format.
use comline_runtime::contract::{Peer, Reason, RuntimeError};
-use comline_runtime::handshake::comline2::{Comline2Handshake, Negotiated};
+use comline_runtime::handshake::comline2::{self as c2, Comline2Handshake, Negotiated};
use comline_runtime::transport::Transport;
/// The package's wire format (`wire.format`).
@@ -29,42 +30,54 @@ pub type Framing = comline_runtime::contract::Datagram3Framing;
/// return, written `Connection`: [`Format`] over [`Framing`].
pub type Connection = comline_runtime::connection::Connection;
-/// This end's `comline@2` Hello: version 0.1.0 of package `0123456789abcdef0123456789abcdef`, as its
-/// history records it. Its protocols, by wire number:
-///
-/// - 0 `conformance::Chat`, line 0.1.0: `send` 0
-/// - 1 `conformance::Events`, line 0.1.0: `shown` 1, `ping` 0
+/// What this end's `comline@2` Hello holds whichever protocols it lists: version 0.1.0 of
+/// package `0123456789abcdef0123456789abcdef`, as its history records it, and the connection's encodings.
+/// [`handshake`] adds the protocols this end provides and calls, one `P_` entry each.
#[doc(hidden)]
-pub const HELLO: &[u8] = &[
- 0x43, 0x4f, 0x02, 0x01, 0x00, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd,
- 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x01, 0x00,
- 0x00, 0x03, 0x00, 0x52, 0x18, 0x5f, 0xd6, 0x09, 0x92, 0xad, 0x43, 0x02,
- 0x9c, 0xc2, 0x99, 0x62, 0xb3, 0xaf, 0xb4, 0x01, 0x4e, 0x6e, 0xde, 0x7c,
- 0xc8, 0xf5, 0xaa, 0x52, 0xce, 0x16, 0x9f, 0x9e, 0x65, 0x67, 0x40, 0xe2,
- 0x02, 0x58, 0x80, 0x9a, 0xaf, 0x4b, 0x47, 0xd5, 0x6c, 0x69, 0xb2, 0xc1,
- 0xfc, 0x9d, 0x43, 0x30, 0xc1, 0x02, 0x00, 0x00, 0x01, 0x00, 0x5a, 0x5a,
- 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
- 0x5a, 0x5a, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x5a, 0x5a, 0x5a, 0x5a,
- 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
- 0x02, 0x00, 0x01,
-];
-
-/// The `comline@2` handshake, with [`HELLO`] and the parameters the package
-/// states: `scope = protocol`, `newer_consumer = degrade`, `same_version_differs = refuse`, `exchange = offer`.
+pub const HEADER: c2::HelloHeader<'static> = c2::HelloHeader {
+ exchange: c2::Exchange::Offer,
+ package_id: c2::Hash128([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]),
+ version: c2::Release::new(0, 1, 0),
+ pre: "",
+ encodings: &[
+ c2::Encoding { kind: c2::EncodingKind::Format, param_hash: c2::Hash128([0x52, 0x18, 0x5f, 0xd6, 0x09, 0x92, 0xad, 0x43, 0x02, 0x9c, 0xc2, 0x99, 0x62, 0xb3, 0xaf, 0xb4]) },
+ c2::Encoding { kind: c2::EncodingKind::Framing, param_hash: c2::Hash128([0x4e, 0x6e, 0xde, 0x7c, 0xc8, 0xf5, 0xaa, 0x52, 0xce, 0x16, 0x9f, 0x9e, 0x65, 0x67, 0x40, 0xe2]) },
+ c2::Encoding { kind: c2::EncodingKind::Handshake, param_hash: c2::Hash128([0x58, 0x80, 0x9a, 0xaf, 0x4b, 0x47, 0xd5, 0x6c, 0x69, 0xb2, 0xc1, 0xfc, 0x9d, 0x43, 0x30, 0xc1]) },
+ ],
+};
+
+/// `conformance::Chat`, wire number 0, line 0.1.0: `send` 0
#[doc(hidden)]
-pub fn handshake() -> Comline2Handshake {
- use comline_runtime::handshake::comline2 as c2;
- let hello = match c2::Message::decode(HELLO) {
- Ok(c2::Message::Hello(hello)) => hello,
- _ => unreachable!("HELLO is a Hello message"),
- };
+pub const P_CONFORMANCE_CHAT: c2::ProtocolEntry<'static> = c2::ProtocolEntry {
+ number: 0,
+ line: c2::Release::new(0, 1, 0),
+ shape_hash: c2::Hash128([0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a]),
+ functions: &[0],
+};
+
+/// `conformance::Events`, wire number 1, line 0.1.0: `shown` 1, `ping` 0
+#[doc(hidden)]
+pub const P_CONFORMANCE_EVENTS: c2::ProtocolEntry<'static> = c2::ProtocolEntry {
+ number: 1,
+ line: c2::Release::new(0, 1, 0),
+ shape_hash: c2::Hash128([0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a]),
+ functions: &[0, 1],
+};
+
+/// The `comline@2` handshake, with the parameters the package states:
+/// `scope = protocol`, `newer_consumer = degrade`, `same_version_differs = refuse`, `exchange = offer`.
+/// Its Hello lists the protocols `provided` and `called` and no others: the
+/// peer refuses a listed protocol it doesn't have, and a protocol left out is
+/// neither provided nor called on the connection.
+#[doc(hidden)]
+pub fn handshake(provided: &[c2::ProtocolEntry<'_>], called: &[c2::ProtocolEntry<'_>]) -> Comline2Handshake {
let params = c2::Params {
scope: c2::Scope::Protocol,
newer_consumer: c2::NewerConsumer::Degrade,
same_version_differs: c2::SameVersionDiffers::Refuse,
exchange: c2::Exchange::Offer,
};
- c2::Comline2Handshake::new(params, hello)
+ c2::Comline2Handshake::new(params, c2::Hello::build(&HEADER, provided, called))
}
/// The package's protocols on the connection, by wire number.
@@ -154,29 +167,146 @@ pub fn check_call(peer: &mut P, protocol: u16, function: u16, path: &'s
Err(error)
}
-/// What the accepting side provides: one field per protocol, so leaving one out
-/// doesn't compile.
+/// A protocol left out of [`Services`] or [`ClientServices`]: it isn't provided,
+/// and the `comline@2` Hello doesn't list it unless this end calls it.
+#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
+pub struct Absent;
+
+/// What provides `conformance::Chat` in [`Services`] or [`ClientServices`]: its trait's implementor, or [`Absent`].
+#[doc(hidden)]
+pub trait ProvideConformanceChat {
+ /// Its entry in the Hello, when something provides it.
+ const ENTRY: Option>;
+ fn provide(self, conn: &mut Connection) -> Result<(), RuntimeError>;
+}
+
+impl ProvideConformanceChat for Absent {
+ const ENTRY: Option> = None;
+ fn provide(self, _conn: &mut Connection) -> Result<(), RuntimeError> {
+ Ok(())
+ }
+}
+
+impl ProvideConformanceChat for P {
+ const ENTRY: Option> = Some(P_CONFORMANCE_CHAT);
+ fn provide(self, conn: &mut Connection) -> Result<(), RuntimeError> {
+ crate::conformance::ChatDispatcher(self).provide_on(conn)
+ }
+}
+
+/// What provides `conformance::Events` in [`Services`] or [`ClientServices`]: its trait's implementor, or [`Absent`].
+#[doc(hidden)]
+pub trait ProvideConformanceEvents {
+ /// Its entry in the Hello, when something provides it.
+ const ENTRY: Option>;
+ fn provide(self, conn: &mut Connection) -> Result<(), RuntimeError>;
+}
+
+impl ProvideConformanceEvents for Absent {
+ const ENTRY: Option> = None;
+ fn provide(self, _conn: &mut Connection) -> Result<(), RuntimeError> {
+ Ok(())
+ }
+}
+
+impl ProvideConformanceEvents for P {
+ const ENTRY: Option> = Some(P_CONFORMANCE_EVENTS);
+ fn provide(self, conn: &mut Connection) -> Result<(), RuntimeError> {
+ crate::conformance::EventsDispatcher(self).provide_on(conn)
+ }
+}
+
+/// What the accepting side provides: one field per protocol. Every field is a
+/// protocol's implementation, or [`Absent`] to leave the protocol out;
+/// `Services::new()` has them all absent, and `with_` provides one.
pub struct Services {
pub chat: Chat,
}
-impl Services {
- /// Provide every protocol on `conn`: the peer's calls to them come here.
- pub fn provide_on(self, conn: &mut Connection) {
- crate::conformance::ChatDispatcher(self.chat).provide_on(conn);
+impl Services {
+ /// Nothing provided yet.
+ pub fn new() -> Self {
+ Services {
+ chat: Absent,
+ }
}
}
-/// What the dialling side provides: one field per protocol, so leaving one out
-/// doesn't compile.
+impl Default for Services {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+impl