Skip to content

Commit

Permalink
Merge pull request #7 from plabayo/feat/rama-rt
Browse files Browse the repository at this point in the history
introduce rama-rt to isolate runtime (tokio) usage
  • Loading branch information
GlenDC authored Nov 28, 2023
2 parents 16b9ffb + 1d75eac commit b8f8385
Show file tree
Hide file tree
Showing 64 changed files with 1,181 additions and 302 deletions.
85 changes: 21 additions & 64 deletions Cargo.lock

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

11 changes: 4 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = [".", "rama-cli", "rama-rt"]
members = [".", "rama-cli", "rama-rt", "rama-rt-macros"]

[workspace.package]
version = "0.2.0"
Expand Down Expand Up @@ -28,15 +28,14 @@ http-body = "1"
http-body-util = "0.1"
httparse = "1.8"
hyper = { package = "rama-hyper", version = "0.1000001", features = ["http1", "http2", "server"] }
hyper-util = { package = "rama-hyper-util", version = "0.1001", features = ["tokio", "server-auto"] }
hyper-util = { package = "rama-hyper-util", version = "0.1001", features = ["server-auto"] }
matchit = "0.4.2"
pin-project-lite = "0.2.13"
rama-rt = { version = "0.2", path = "./rama-rt" }
rama-rt-macros = { version = "0.2", path = "./rama-rt-macros" }
rustls = "0.22.0-alpha.3"
serde = { version = "1.0", features = ["derive"] }
serde_urlencoded = "0.7"
tokio = { version = "1.33", features = ["net", "io-util"] }
tokio-graceful = "0.1"
tokio-rustls = "0.25.0-alpha.1"
tower-async = { version = "0.2", features = [
"util",
"timeout",
Expand All @@ -50,6 +49,4 @@ tracing = "0.1"
futures = "0.3.29"
pki-types = { package = "rustls-pki-types", version = "0.2.1" }
rcgen = "0.11.3"
tokio = { version = "1.33.0", features = ["full"] }
tokio-test = "0.4.3"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
6 changes: 3 additions & 3 deletions examples/tokio_tcp_echo_server.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::time::Duration;

use rama::{
graceful::Shutdown,
server::tcp::TcpListener,
rt::graceful::Shutdown,
service::{limit::ConcurrentPolicy, Layer, Service},
state::Extendable,
stream::layer::BytesRWTrackerHandle,
stream::service::EchoService,
tcp::server::TcpListener,
};

use tracing::metadata::LevelFilter;
use tracing_subscriber::{fmt, prelude::*, EnvFilter};

#[rama::main]
#[rama::rt::main]
async fn main() {
tracing_subscriber::registry()
.with(fmt::layer())
Expand Down
4 changes: 2 additions & 2 deletions examples/tokio_tcp_hello.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rama::{server::tcp::TcpListener, stream::AsyncWriteExt};
use rama::{rt::io::AsyncWriteExt, tcp::server::TcpListener};

#[rama::main]
#[rama::rt::main]
async fn main() {
TcpListener::bind("127.0.0.1:9000")
.await
Expand Down
16 changes: 8 additions & 8 deletions examples/tokio_tcp_http_hello.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use std::{convert::Infallible, time::Duration};

use rama::{
graceful::Shutdown,
net::http::StatusCode,
net::TcpStream,
server::tcp::http,
server::tcp::TcpListener,
http::server as http,
http::StatusCode,
rt::graceful::Shutdown,
service::{limit::ConcurrentPolicy, Layer, Service},
state::Extendable,
stream::{layer::BytesRWTrackerHandle, Stream},
tcp::server::TcpListener,
tcp::TcpStream,
};

use tracing::metadata::LevelFilter;
use tracing_subscriber::{fmt, prelude::*, EnvFilter};

#[rama::main]
#[rama::rt::main]
async fn main() {
tracing_subscriber::registry()
.with(fmt::layer())
Expand Down Expand Up @@ -158,11 +158,11 @@ impl WebServer {
}

async fn render_page_fast(&self) -> Response {
self.render_page(rama::net::http::StatusCode::OK, "This was a fast response.")
self.render_page(StatusCode::OK, "This was a fast response.")
}

async fn render_page_slow(&self) -> Response {
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
rama::rt::time::sleep(std::time::Duration::from_secs(5)).await;
self.render_page(StatusCode::OK, "This was a slow response.")
}

Expand Down
15 changes: 6 additions & 9 deletions examples/tokio_tls_proxy.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
use std::time::Duration;

use rama::{
graceful::Shutdown,
server::{
tcp::TcpListener,
tls::rustls::{RustlsAcceptorLayer, RustlsServerConfig},
},
stream::AsyncWriteExt,
rt::{graceful::Shutdown, io::AsyncWriteExt},
tcp::server::TcpListener,
tls::server::rustls::{RustlsAcceptorLayer, RustlsServerConfig},
};

use pki_types::{CertificateDer, PrivatePkcs8KeyDer};
use tracing::metadata::LevelFilter;
use tracing_subscriber::{fmt, prelude::*, EnvFilter};

#[rama::main]
#[rama::rt::main]
async fn main() {
tracing_subscriber::registry()
.with(fmt::layer())
Expand Down Expand Up @@ -73,8 +70,8 @@ async fn main() {
))
.serve_fn_graceful(guard, |mut stream| async move {
let result = async {
let mut target_stream = rama::client::tcp::connect("127.0.0.1:8080").await?;
match rama::io::copy_bidirectional(&mut stream, &mut target_stream).await {
let mut target_stream = rama::tcp::client::connect("127.0.0.1:8080").await?;
match rama::rt::io::copy_bidirectional(&mut stream, &mut target_stream).await {
Ok(_) => Ok(()),
Err(err) => {
if err.kind() == std::io::ErrorKind::ConnectionReset {
Expand Down
2 changes: 1 addition & 1 deletion rama-book/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ authors = ["Glen De Cauwsemaecker <[email protected]>"]
language = "en"
multilingual = false
src = "src"
title = "Rama Book"
title = "Rama"
2 changes: 1 addition & 1 deletion rama-book/src/preface.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![rama banner](https://raw.githubusercontent.com/plabayo/rama/main/docs/img/banner.svg)](https://raw.githubusercontent.com/plabayo/rama/main/docs/img/banner.svg)

# Rama Book
# Rama

[![Crates.io][crates-badge]][crates-url]
[![Docs.rs][docs-badge]][docs-url]
Expand Down
1 change: 1 addition & 0 deletions rama-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "rama-cli"
description = "binary version of and cli utility for rama, a distortion proxy framework"
version = { workspace = true }
license = { workspace = true }
edition = { workspace = true }
Expand Down
27 changes: 27 additions & 0 deletions rama-rt-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "rama-rt-macros"
description = "macros in function of rama-rt"
version = { workspace = true }
license = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }
keywords = { workspace = true }
categories = { workspace = true }
authors = { workspace = true }
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
proc-macro = true

[features]

[dependencies]
proc-macro2 = "1.0.70"
quote = "1"
syn = { version = "2.0", features = ["full"] }

[dev-dependencies]
rama = { version = "0.2", path = ".." }

[package.metadata.docs.rs]
all-features = true
Loading

0 comments on commit b8f8385

Please sign in to comment.