Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(iroh-router)!: change accept to take an AsRef<[u8]> #2963

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion iroh-router/examples/custom-protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async fn main() -> Result<()> {
let builder = Router::builder(endpoint);

// Add our protocol, identified by our ALPN, to the node, and spawn the node.
let router = builder.accept(ALPN.to_vec(), proto.clone()).spawn().await?;
let router = builder.accept(ALPN, proto.clone()).spawn().await?;

match args.command {
Command::Listen { text } => {
Expand Down
4 changes: 2 additions & 2 deletions iroh-router/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ impl RouterBuilder {
}
}

pub fn accept(mut self, alpn: Vec<u8>, handler: Arc<dyn ProtocolHandler>) -> Self {
self.protocols.insert(alpn, handler);
pub fn accept(mut self, alpn: impl AsRef<[u8]>, handler: Arc<dyn ProtocolHandler>) -> Self {
self.protocols.insert(alpn.as_ref().to_vec(), handler);
self
}

Expand Down
4 changes: 2 additions & 2 deletions iroh/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,14 +579,14 @@ impl ProtocolBuilder {
/// let handler = MyProtocol { client };
///
/// let node = unspawned_node
/// .accept(MY_ALPN.to_vec(), Arc::new(handler))
/// .accept(MY_ALPN, Arc::new(handler))
/// .spawn()
/// .await?;
/// # node.shutdown().await?;
/// # Ok(())
/// # }
/// ```
pub fn accept(mut self, alpn: Vec<u8>, handler: Arc<dyn ProtocolHandler>) -> Self {
pub fn accept(mut self, alpn: impl AsRef<[u8]>, handler: Arc<dyn ProtocolHandler>) -> Self {
self.router = self.router.accept(alpn, handler);
self
}
Expand Down
Loading