make extensions owned

This commit is contained in:
Toshit Chawda 2024-04-13 23:45:40 -07:00
parent 76da9fd619
commit ace9bf380d
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D
6 changed files with 21 additions and 23 deletions

View file

@ -112,7 +112,7 @@ pub mod udp {
//! rx,
//! tx,
//! 128,
//! Some(&[&UdpProtocolExtensionBuilder()])
//! Some(&[Box::new(UdpProtocolExtensionBuilder())])
//! );
//! ```
//! See [the docs](https://github.com/MercuryWorkshop/wisp-protocol/blob/main/protocol.md#0x01---udp)
@ -213,7 +213,7 @@ pub mod password {
//! rx,
//! tx,
//! 128,
//! Some(&[&PasswordProtocolExtensionBuilder::new_server(passwords)])
//! Some(&[Box::new(PasswordProtocolExtensionBuilder::new_server(passwords))])
//! );
//! ```
//!
@ -224,10 +224,10 @@ pub mod password {
//! tx,
//! 128,
//! Some(&[
//! &PasswordProtocolExtensionBuilder::new_client(
//! Box::new(PasswordProtocolExtensionBuilder::new_client(
//! "user1".to_string(),
//! "pw".to_string()
//! )
//! ))
//! ])
//! );
//! ```

View file

@ -445,7 +445,7 @@ impl MuxInner {
/// ```
/// use wisp_mux::ServerMux;
///
/// let (mux, fut) = ServerMux::new(rx, tx, 128, Some(vec![]), Some([]));
/// let (mux, fut) = ServerMux::new(rx, tx, 128, Some([]));
/// tokio::spawn(async move {
/// if let Err(e) = fut.await {
/// println!("error in multiplexor: {:?}", e);
@ -472,14 +472,14 @@ pub struct ServerMux {
impl ServerMux {
/// Create a new server-side multiplexor.
///
/// If extension_builders is None a Wisp v1 connection is created otherwise a Wisp v2 connection is created.
/// If `extension_builders` is None a Wisp v1 connection is created otherwise a Wisp v2 connection is created.
/// **It is not guaranteed that all extensions you specify are available.** You must manually check
/// if the extensions you need are available after the multiplexor has been created.
pub async fn new<R, W>(
mut read: R,
write: W,
buffer_size: u32,
extension_builders: Option<&[&(dyn ProtocolExtensionBuilder + Sync)]>,
extension_builders: Option<&[Box<dyn ProtocolExtensionBuilder + Send + Sync>]>,
) -> Result<(Self, impl Future<Output = Result<(), WispError>> + Send), WispError>
where
R: ws::WebSocketRead + Send,
@ -581,7 +581,7 @@ impl ServerMux {
/// ```
/// use wisp_mux::{ClientMux, StreamType};
///
/// let (mux, fut) = ClientMux::new(rx, tx, Some(vec![]), []).await?;
/// let (mux, fut) = ClientMux::new(rx, tx, Some([])).await?;
/// tokio::spawn(async move {
/// if let Err(e) = fut.await {
/// println!("error in multiplexor: {:?}", e);
@ -602,13 +602,13 @@ pub struct ClientMux {
impl ClientMux {
/// Create a new client side multiplexor.
///
/// If extension_builders is None a Wisp v1 connection is created otherwise a Wisp v2 connection is created.
/// If `extension_builders` is None a Wisp v1 connection is created otherwise a Wisp v2 connection is created.
/// **It is not guaranteed that all extensions you specify are available.** You must manually check
/// if the extensions you need are available after the multiplexor has been created.
pub async fn new<R, W>(
mut read: R,
write: W,
extension_builders: Option<&[&(dyn ProtocolExtensionBuilder + Sync)]>,
extension_builders: Option<&[Box<dyn ProtocolExtensionBuilder + Send + Sync>]>,
) -> Result<(Self, impl Future<Output = Result<(), WispError>> + Send), WispError>
where
R: ws::WebSocketRead + Send,

View file

@ -380,7 +380,7 @@ impl Packet {
pub(crate) fn maybe_parse_info(
frame: Frame,
role: Role,
extension_builders: &[&(dyn ProtocolExtensionBuilder + Sync)],
extension_builders: &[Box<(dyn ProtocolExtensionBuilder + Send + Sync)>],
) -> Result<Self, WispError> {
if !frame.finished {
return Err(WispError::WsFrameNotFinished);
@ -431,7 +431,7 @@ impl Packet {
fn parse_info(
mut bytes: Bytes,
role: Role,
extension_builders: &[&(dyn ProtocolExtensionBuilder + Sync)],
extension_builders: &[Box<(dyn ProtocolExtensionBuilder + Send + Sync)>],
) -> Result<Self, WispError> {
// packet type is already read by code that calls this
if bytes.remaining() < 4 + 2 {