Skip to content

Commit

Permalink
Simplify passing connection params
Browse files Browse the repository at this point in the history
  • Loading branch information
MOZGIII committed Jul 21, 2023
1 parent c2114d2 commit 3d3f089
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions crates/xwebtransport-core/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ pub trait Connecting: maybe::Send {
#[cfg_attr(not(target_family = "wasm"), async_trait)]
#[cfg_attr(target_family = "wasm", async_trait(?Send))]
pub trait EndpointConnect: Sized + maybe::Send {
type Params<'params>;
type Params;
type Connecting: Connecting;
type Error: std::error::Error + maybe::Send + maybe::Sync + 'static;

async fn connect(
&self,
url: &str,
params: Self::Params<'_>,
params: &Self::Params,
) -> Result<Self::Connecting, Self::Error>;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/xwebtransport-tests/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ where

pub async fn echo<Endpoint>(
endpoint: Endpoint,
params: Endpoint::Params<'_>,
params: &Endpoint::Params,
) -> Result<(), EchoError<Endpoint>>
where
Endpoint: xwebtransport_core::EndpointConnect + std::fmt::Debug,
Expand Down
2 changes: 1 addition & 1 deletion crates/xwebtransport-tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use xwebtransport_core::prelude::*;
pub async fn connect<Endpoint>(
endpoint: Endpoint,
url: &str,
params: Endpoint::Params<'_>,
params: &Endpoint::Params,
) -> Result<EndpointConnectConnectionFor<Endpoint>, xwebtransport_error::Connect<Endpoint>>
where
Endpoint: xwebtransport_core::EndpointConnect,
Expand Down
4 changes: 2 additions & 2 deletions crates/xwebtransport-web-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ pub struct Endpoint;
#[async_trait(?Send)]
impl xwebtransport_core::traits::EndpointConnect for Endpoint {
type Error = Error;
type Params<'params> = &'params web_sys::WebTransportOptions;
type Params = web_sys::WebTransportOptions;
type Connecting = xwebtransport_core::utils::dummy::Connecting<Connection>;

async fn connect(
&self,
url: &str,
params: Self::Params<'_>,
params: &Self::Params,
) -> Result<Self::Connecting, Self::Error> {
let transport = web_sys::WebTransport::new_with_options(url, params)?;
let _ = wasm_bindgen_futures::JsFuture::from(transport.ready()).await?;
Expand Down
4 changes: 2 additions & 2 deletions crates/xwebtransport-wtransport/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ pub use self::types::*;

#[async_trait]
impl xwebtransport_core::traits::EndpointConnect for Endpoint<wtransport::endpoint::Client> {
type Params<'params> = ();
type Params = ();
type Connecting = xwebtransport_core::utils::dummy::Connecting<Connection>;
type Error = wtransport::error::ConnectingError;

async fn connect(
&self,
url: &str,
_params: Self::Params<'_>,
_params: &Self::Params,
) -> Result<Self::Connecting, Self::Error> {
let connecting = self.0.connect(url).await.map(Connection)?;
Ok(xwebtransport_core::utils::dummy::Connecting(connecting))
Expand Down
2 changes: 1 addition & 1 deletion crates/xwebtransport-wtransport/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn main() {

let endpoint = xwebtransport_wtransport::Endpoint(endpoint);

xwebtransport_tests::tests::echo(endpoint, ())
xwebtransport_tests::tests::echo(endpoint, &())
.await
.unwrap();
}

0 comments on commit 3d3f089

Please sign in to comment.