Skip to content

Commit

Permalink
Merge pull request #196 from c410-f3r/rrrrr
Browse files Browse the repository at this point in the history
Breaking free from the constraints of `AsyncBounds`
  • Loading branch information
c410-f3r authored Jul 26, 2024
2 parents d6177e4 + e6589b9 commit 93e7b5c
Show file tree
Hide file tree
Showing 52 changed files with 402 additions and 407 deletions.
1 change: 0 additions & 1 deletion .scripts/internal-tests0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ cargo miri test -p wtx
$rt check-generic wtx
$rt test-with-features wtx ahash
$rt test-with-features wtx arbitrary
$rt test-with-features wtx async-send
$rt test-with-features wtx async-std
$rt test-with-features wtx atoi
$rt test-with-features wtx base64
Expand Down
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![crates.io](https://img.shields.io/crates/v/wtx.svg)](https://crates.io/crates/wtx)
[![Documentation](https://docs.rs/wtx/badge.svg)](https://docs.rs/wtx)
[![License](https://img.shields.io/badge/license-APACHE2-blue.svg)](https://github.com/c410-f3r/wtx/blob/main/LICENSE)
[![Rustc](https://img.shields.io/badge/rustc-1.80-lightgray")](https://blog.rust-lang.org/2023/12/28/Rust-1.80.0.html)
[![Rustc](https://img.shields.io/badge/rustc-nightly-blue")](https://blog.rust-lang.org/2023/12/28/Rust-1.80.0.html)

A collection of different transport implementations and related tools focused primarily on web technologies. Contains the implementations of 4 IETF RFCs ([RFC6455](https://datatracker.ietf.org/doc/html/rfc6455), [RFC7541](https://datatracker.ietf.org/doc/html/rfc7541), [RFC7692](https://datatracker.ietf.org/doc/html/rfc7692), [RFC9113](https://datatracker.ietf.org/doc/html/rfc9113)), 1 formal specification ([PostgreSQL](https://www.postgresql.org/docs/16/protocol.html)) and several other invented ideas.

Expand Down
2 changes: 1 addition & 1 deletion wtx-docs/src/http-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern crate wtx;
use wtx::{
http::{Client, Method, ReqResBuffer, ReqUri},
misc::{from_utf8_basic, TokioRustlsConnector, Uri},
misc::{from_utf8_basic, TokioRustlsConnector},
};
pub(crate) async fn get_and_print() -> wtx::Result<()> {
Expand Down
6 changes: 4 additions & 2 deletions wtx-fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
cargo-features = ["edition2024"]

[[bin]]
name = "web-socket"
path = "web_socket.rs"
Expand All @@ -9,10 +11,10 @@ tokio = { default-features = false, features = ["rt"], version = "1.0" }
wtx = { default-features = false, features = ["arbitrary", "web-socket"], path = "../wtx" }

[package]
edition = "2024"
name = "wtx-fuzz"
version = "0.0.0"
publish = false
edition = "2021"
version = "0.0.0"

[package.metadata]
cargo-fuzz = true
4 changes: 3 additions & 1 deletion wtx-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
cargo-features = ["edition2024"]

[dependencies]
proc-macro2 = { default-features = false, version = "1.0" }
quote = { default-features = false, features = ["proc-macro"], version = "1.0" }
Expand All @@ -16,7 +18,7 @@ proc-macro = true
[package]
categories = ["asynchronous", "data-structures", "network-programming"]
description = "Procedural macros for wtx"
edition = "2021"
edition = "2024"
exclude = ["tests"]
keywords = ["api", "client", "io", "network"]
license = "MIT"
Expand Down
1 change: 0 additions & 1 deletion wtx-macros/src/pkg/sir/sir_final_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ impl<'attrs, 'module, 'others>
#res_ident
>: wtx::client_api_framework::dnsn::Deserialize<DRSR>,
A: wtx::client_api_framework::Api<Error = <#api as wtx::client_api_framework::Api>::Error> + wtx::misc::LeaseMut<#api>,
DRSR: wtx::misc::AsyncBounds,
{
type ExternalRequestContent = wtx::client_api_framework::data_format::#dfe_ext_req_ctnt_wrapper<
#freqdiv_ident<#freqdiv_params>
Expand Down
6 changes: 5 additions & 1 deletion wtx-ui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
cargo-features = ["edition2024"]

[dependencies]
clap = { default-features = false, features = ["derive", "help", "std", "usage"], optional = true, version = "4.5" }
dotenv = { default-features = false, optional = true, version = "0.15" }
tokio = { default-features = false, features = ["io-std", "io-util", "macros", "net", "rt-multi-thread"], version = "1.0" }
wtx = { default-features = false, features = ["tokio"], path = "../wtx" }

[features]
clap = ["dep:clap"]
default = []
dotenv = ["dep:dotenv"]
embed-migrations = ["clap", "tokio/fs", "wtx/schema-manager", "wtx/std"]
http-client = ["clap", "wtx/http-client", "wtx/tokio-rustls", "wtx/webpki-roots"]
schema-manager = ["clap", "wtx/postgres", "wtx/schema-manager", "wtx/std"]
Expand All @@ -17,7 +21,7 @@ authors = ["Caio Fernandes <[email protected]>"]
categories = ["asynchronous", "command-line-interface", "gui"]
description = "Different user interfaces for WTX"
documentation = "https://docs.rs/wtx-ui"
edition = "2021"
edition = "2024"
keywords = ["io", "network", "websocket"]
license = "Apache-2.0"
name = "wtx-ui"
Expand Down
42 changes: 36 additions & 6 deletions wtx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
cargo-features = ["edition2024"]

[[bin]]
name = "autobahn-client"
path = "src/bin/autobahn-client.rs"
Expand Down Expand Up @@ -99,40 +101,68 @@ tokio = { default-features = false, features = ["macros", "net", "rt-multi-threa
[features]
ahash = ["dep:ahash", "hashbrown?/ahash"]
arbitrary = ["dep:arbitrary", "std"]
async-send = ["parking_lot?/send_guard"]
async-std = ["dep:async-std", "std"]
atoi = ["dep:atoi"]
base64 = ["dep:base64"]
borsh = ["dep:borsh", "std"]
chrono = ["dep:chrono"]
cl-aux = ["dep:cl-aux"]
client-api-framework = ["cl-aux"]
crypto-common = ["dep:crypto-common"]
database = []
default = []
digest = ["dep:digest"]
embassy-net = ["dep:embassy-net"]
embassy-sync = ["dep:embassy-sync"]
embassy-time = ["dep:embassy-time"]
embedded-tls = ["dep:embedded-io-async", "dep:embedded-tls"]
fastrand = ["dep:fastrand"]
flate2 = ["dep:flate2"]
futures-lite = ["dep:futures-lite"]
glommio = ["futures-lite", "dep:glommio", "std"]
grpc = ["http2"]
hashbrown = ["dep:hashbrown"]
hmac = ["dep:hmac"]
http-client = ["http2", "pool"]
http1 = ["httparse"]
http2 = ["ahash", "hashbrown"]
http2 = ["ahash", "hashbrown", "tokio"]
httparse = ["dep:httparse"]
memchr = ["dep:memchr"]
miniserde = ["dep:miniserde", "std"]
optimization = ["atoi", "memchr", "simdutf8"]
parking_lot = ["dep:parking_lot"]
pool = []
postgres = ["ahash", "base64", "crypto-common", "database", "digest", "hashbrown", "hmac", "sha2"]
proptest = ["dep:proptest"]
protobuf = ["dep:protobuf", "std"]
rand = ["dep:rand"]
ring = ["dep:ring"]
rkyv = ["dep:rkyv"]
rust_decimal = ["dep:rust_decimal"]
rustls-pemfile = ["dep:rustls-pemfile"]
rustls-pki-types = ["dep:rustls-pki-types"]
schema-manager = ["database", "chrono"]
schema-manager-dev = ["schema-manager"]
serde = ["cl-aux?/serde", "dep:serde"]
serde_json = ["serde", "dep:serde_json", "std"]
serde_yaml = ["serde", "dep:serde_yaml", "std"]
serde-xml-rs = ["serde", "dep:serde-xml-rs", "std"]
sha1 = ["dep:sha1"]
sha2 = ["dep:sha2"]
simd-json = ["serde", "dep:simd-json", "std"]
simdutf8 = ["dep:simdutf8"]
smol = ["dep:smol", "std"]
smoltcp = ["dep:smoltcp"]
std = ["ahash?/std", "atoi?/std", "cl-aux?/std", "embassy-sync?/std", "memchr?/std", "miniserde?/std", "serde?/std", "serde_json?/std", "simdutf8?/std"]
test-strategy = ["dep:test-strategy", "proptest"]
tokio = ["async-send", "std", "dep:tokio"]
tokio = ["std", "dep:tokio"]
tokio-rustls = ["ring", "rustls-pki-types", "tokio", "dep:tokio-rustls"]
tracing = ["dep:tracing"]
web-socket = []
web-socket-handshake = ["base64", "http1", "sha1", "web-socket"]
webpki-roots = ["dep:webpki-roots"]
x509-certificate = ["dep:x509-certificate"]

_bench = []
# It is not up to this crate to decide what downstream should use
_hack = ["embassy-net?/medium-ip", "embassy-net?/proto-ipv4", "rkyv?/size_32", "simd-json?/allow-non-simd", "smoltcp?/medium-ip", "smoltcp?/proto-ipv4", "smoltcp?/socket-tcp"]
_integration-tests = ["serde_json?/raw_value"]
_proptest = ["proptest/std", "rust_decimal?/proptest", "std", "test-strategy"]
Expand All @@ -144,7 +174,7 @@ authors = ["Caio Fernandes <[email protected]>"]
categories = ["asynchronous", "database", "network-programming", "no-std", "web-programming"]
description = "A collection of different transport implementations and related tools focused primarily on web technologies."
documentation = "https://docs.rs/wtx"
edition = "2021"
edition = "2024"
exclude = ["examples", "src/bin", "tests"]
homepage = "https://c410-f3r.github.io/wtx"
keywords = ["api", "database", "http", "network", "websocket"]
Expand Down
8 changes: 3 additions & 5 deletions wtx/examples/http2-server-tokio-rustls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
mod common;

use wtx::{
http::{server::OptionedServer, ReqResBuffer, Request, Response, StatusCode},
http::{server::OptionedServer, ReqResBuffer, Request, StatusCode},
http2::{Http2Buffer, Http2Params},
misc::TokioRustlsAcceptor,
rng::StdRng,
Expand Down Expand Up @@ -32,9 +32,7 @@ async fn main() {
.unwrap()
}

async fn handle<'buffer>(
req: Request<&'buffer mut ReqResBuffer>,
) -> Result<Response<&'buffer mut ReqResBuffer>, wtx::Error> {
async fn handle(req: &mut Request<&mut ReqResBuffer>) -> Result<StatusCode, wtx::Error> {
req.rrd.clear();
Ok(Response::http2(req.rrd, StatusCode::Ok))
Ok(StatusCode::Ok)
}
8 changes: 3 additions & 5 deletions wtx/src/bin/h2spec-server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! h2spec
use wtx::{
http::{server::OptionedServer, ReqResBuffer, Request, Response, StatusCode},
http::{server::OptionedServer, ReqResBuffer, Request, StatusCode},
http2::{Http2Buffer, Http2Params},
rng::StdRng,
};
Expand All @@ -21,10 +21,8 @@ async fn main() {
.unwrap()
}

async fn handle(
req: Request<&mut ReqResBuffer>,
) -> Result<Response<&mut ReqResBuffer>, wtx::Error> {
async fn handle(req: &mut Request<&mut ReqResBuffer>) -> Result<StatusCode, wtx::Error> {
req.rrd.clear();
req.rrd.extend_body(b"Hello").unwrap();
Ok(Response::http2(req.rrd, StatusCode::Ok))
Ok(StatusCode::Ok)
}
9 changes: 4 additions & 5 deletions wtx/src/client_api_framework/api.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::misc::AsyncBounds;
use core::{fmt::Display, future::Future};
use core::fmt::Display;

/// Api definitions group different packages into a common namespace and define custom additional
/// logical through hooks.
Expand All @@ -9,13 +8,13 @@ pub trait Api {

/// Fallible hook that is automatically called after sending any related request.
#[inline]
fn after_sending(&mut self) -> impl AsyncBounds + Future<Output = Result<(), Self::Error>> {
fn after_sending(&mut self) -> impl Future<Output = Result<(), Self::Error>> {
async { Ok(()) }
}

/// Fallible hook that is automatically called before sending any related request.
#[inline]
fn before_sending(&mut self) -> impl AsyncBounds + Future<Output = Result<(), Self::Error>> {
fn before_sending(&mut self) -> impl Future<Output = Result<(), Self::Error>> {
async { Ok(()) }
}
}
Expand All @@ -26,7 +25,7 @@ impl Api for () {

impl<T> Api for &mut T
where
T: Api + AsyncBounds,
T: Api,
{
type Error = T::Error;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
client_api_framework::{dnsn::Serialize, Id},
misc::Vector,
misc::{Lease, Vector},
};
use core::{
borrow::Borrow,
Expand Down Expand Up @@ -47,6 +47,13 @@ impl<P> Hash for JsonRpcRequest<P> {
}
}

impl<P> Lease<Id> for JsonRpcRequest<P> {
#[inline]
fn lease(&self) -> &Id {
&self.id
}
}

impl<P> Ord for JsonRpcRequest<P> {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
dnsn::{Deserialize, Serialize},
Id,
},
misc::Vector,
misc::{Lease, Vector},
};
use alloc::string::String;
use core::{
Expand Down Expand Up @@ -69,6 +69,13 @@ impl<R> Hash for JsonRpcResponse<R> {
}
}

impl<P> Lease<Id> for JsonRpcResponse<P> {
#[inline]
fn lease(&self) -> &Id {
&self.id
}
}

impl<R> Ord for JsonRpcResponse<R> {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
Expand Down
2 changes: 1 addition & 1 deletion wtx/src/client_api_framework/network/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
};
pub use bi_transport::*;
use cl_aux::DynContigColl;
use core::{borrow::Borrow, future::Future, ops::Range};
use core::{borrow::Borrow, ops::Range};
pub use mock::*;
pub use transport_params::*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
},
misc::Lease,
};
use core::{future::Future, ops::Range};
use core::ops::Range;

/// Bidirectional Transport
///
Expand Down
8 changes: 2 additions & 6 deletions wtx/src/client_api_framework/network/transport/wtx_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ use crate::{
},
http::{Client, Header, Headers, KnownHeaderName, ReqResBuffer},
http2::{Http2, Http2Buffer, Http2Data},
misc::{AsyncBounds, Lock, RefCounter, Stream, Vector},
misc::{Lock, RefCounter, Stream, Vector},
pool::SimplePoolResource,
};
use core::{future::Future, mem, ops::Range};
use core::{mem, ops::Range};

impl<DRSR, HD, RL, S, SF> Transport<DRSR> for Client<HD, RL, SF>
where
DRSR: AsyncBounds,

HD: RefCounter + 'static,
HD::Item: Lock<Resource = Http2Data<Http2Buffer<ReqResBuffer>, ReqResBuffer, S, true>>,
RL: Lock<Resource = SimplePoolResource<Http2<HD, true>>> + 'static,
Expand Down Expand Up @@ -64,9 +62,7 @@ async fn response<A, DRSR, HD, P, RL, S, SF>(
) -> Result<(), A::Error>
where
A: Api,
DRSR: AsyncBounds,
P: Package<A, DRSR, HttpParams>,

HD: RefCounter + 'static,
HD::Item: Lock<Resource = Http2Data<Http2Buffer<ReqResBuffer>, ReqResBuffer, S, true>>,
RL: Lock<Resource = SimplePoolResource<Http2<HD, true>>> + 'static,
Expand Down
1 change: 0 additions & 1 deletion wtx/src/client_api_framework/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::client_api_framework::{
Api,
};
pub use batch_pkg::{BatchElems, BatchPkg};
use core::future::Future;
pub use pkg_with_helper::*;
pub use pkgs_aux::*;

Expand Down
Loading

0 comments on commit 93e7b5c

Please sign in to comment.