Skip to content

Commit

Permalink
feat!: use the extracted type-set crate instead of trillium_http::S…
Browse files Browse the repository at this point in the history
…tateSet
  • Loading branch information
jbr committed May 30, 2024
1 parent cf30098 commit 3d71146
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 212 deletions.
2 changes: 1 addition & 1 deletion channels/src/channel_conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A ChannelConn is a wrapper around a [`WebSocketConn`] that also
contains a [`ChannelClient`]
It that provides convenient access to functions from the ChannelClient
held in the WebSocketConn's StateSet, and dereferences to the
held in the WebSocketConn's TypeSet, and dereferences to the
`WebSocketConn` for other functionality.
*/
#[derive(Debug)]
Expand Down
4 changes: 2 additions & 2 deletions channels/src/channel_ext.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{ChannelClient, ChannelEvent};
use serde::Serialize;
use serde_json::Value;
use trillium::StateSet;
use trillium::TypeSet;
macro_rules! unwrap_or_log_and_return {
($expr:expr) => {
match $expr {
Expand Down Expand Up @@ -75,7 +75,7 @@ pub trait ChannelConnExt {

impl<Conn> ChannelConnExt for Conn
where
Conn: AsRef<StateSet>,
Conn: AsRef<TypeSet>,
{
fn channel_client(&self) -> Option<&ChannelClient> {
self.as_ref().get()
Expand Down
4 changes: 2 additions & 2 deletions conn-id/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::{
ops::Deref,
sync::{Arc, Mutex},
};
use trillium::{Conn, Handler, HeaderName, KnownHeaderName, StateSet};
use trillium::{Conn, Handler, HeaderName, KnownHeaderName, TypeSet};

#[derive(Default)]
enum IdGenerator {
Expand Down Expand Up @@ -274,7 +274,7 @@ pub trait ConnIdExt {

impl<ConnLike> ConnIdExt for ConnLike
where
ConnLike: AsRef<StateSet>,
ConnLike: AsRef<TypeSet>,
{
fn id(&self) -> &str {
self.as_ref()
Expand Down
2 changes: 1 addition & 1 deletion handlebars/src/handlebars_conn_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ impl HandlebarsConnExt for Conn {
}

fn assigns_mut(&mut self) -> &mut Assigns {
self.mut_state_or_insert_with(Assigns::default)
self.state_entry().or_default()
}
}
1 change: 1 addition & 0 deletions http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ smartstring = "1.0.1"
thiserror = "1.0.52"
trillium-macros = { version = "0.0.6", path = "../macros" }
swansong = "0.3.0"
type-set = "0.3.0"

[dev-dependencies]
async-compat = "0.2.3"
Expand Down
26 changes: 13 additions & 13 deletions http/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
util::encoding,
Body, BufWriter, Buffer, ConnectionStatus, Error, Headers, HttpConfig,
KnownHeaderName::{Connection, ContentLength, Date, Expect, Host, Server, TransferEncoding},
Method, ReceivedBody, Result, StateSet, Status, Swansong, Upgrade, Version,
Method, ReceivedBody, Result, Status, Swansong, TypeSet, Upgrade, Version,
};
use encoding_rs::Encoding;
use futures_lite::{
Expand Down Expand Up @@ -41,7 +41,7 @@ pub struct Conn<Transport> {
pub(crate) method: Method,
pub(crate) status: Option<Status>,
pub(crate) version: Version,
pub(crate) state: StateSet,
pub(crate) state: TypeSet,
pub(crate) response_body: Option<Body>,
pub(crate) transport: Transport,
pub(crate) buffer: Buffer,
Expand All @@ -52,7 +52,7 @@ pub struct Conn<Transport> {
pub(crate) start_time: Instant,
pub(crate) peer_ip: Option<IpAddr>,
pub(crate) http_config: HttpConfig,
pub(crate) shared_state: Option<Arc<StateSet>>,
pub(crate) shared_state: Option<Arc<TypeSet>>,
}

impl<Transport> Debug for Conn<Transport> {
Expand Down Expand Up @@ -177,7 +177,7 @@ where
http_config: HttpConfig,
transport: Transport,
swansong: Swansong,
shared_state: Option<Arc<StateSet>>,
shared_state: Option<Arc<TypeSet>>,
mut handler: F,
) -> Result<Option<Upgrade<Transport>>>
where
Expand Down Expand Up @@ -222,22 +222,22 @@ where
}

/// returns a read-only reference to the [state
/// typemap](StateSet) for this conn
/// typemap](TypeSet) for this conn
///
/// stability note: this is not unlikely to be removed at some
/// point, as this may end up being more of a trillium concern
/// than a `trillium_http` concern
pub fn state(&self) -> &StateSet {
pub fn state(&self) -> &TypeSet {
&self.state
}

/// returns a mutable reference to the [state
/// typemap](StateSet) for this conn
/// typemap](TypeSet) for this conn
///
/// stability note: this is not unlikely to be removed at some
/// point, as this may end up being more of a trillium concern
/// than a `trillium_http` concern
pub fn state_mut(&mut self) -> &mut StateSet {
pub fn state_mut(&mut self) -> &mut TypeSet {
&mut self.state
}

Expand All @@ -246,7 +246,7 @@ where
/// stability note: this is not unlikely to be removed at some
/// point, as this may end up being more of a trillium concern
/// than a `trillium_http` concern
pub fn shared_state(&self) -> Option<&StateSet> {
pub fn shared_state(&self) -> Option<&TypeSet> {
self.shared_state.as_deref()
}

Expand Down Expand Up @@ -617,7 +617,7 @@ where
mut transport: Transport,
mut buffer: Buffer,
swansong: Swansong,
shared_state: Option<Arc<StateSet>>,
shared_state: Option<Arc<TypeSet>>,
) -> Result<Self> {
use crate::{HeaderName, HeaderValue};
use httparse::{Request, EMPTY_HEADER};
Expand Down Expand Up @@ -685,7 +685,7 @@ where
buffer,
response_headers,
status: None,
state: StateSet::new(),
state: TypeSet::new(),
response_body: None,
request_body_state: ReceivedBodyState::Start,
secure: false,
Expand All @@ -704,7 +704,7 @@ where
mut transport: Transport,
mut buffer: Buffer,
swansong: Swansong,
shared_state: Option<Arc<StateSet>>,
shared_state: Option<Arc<TypeSet>>,
) -> Result<Self> {
let (head_size, start_time) =
Self::head(&mut transport, &mut buffer, &swansong, &http_config).await?;
Expand Down Expand Up @@ -751,7 +751,7 @@ where
buffer,
response_headers,
status: None,
state: StateSet::new(),
state: TypeSet::new(),
response_body: None,
request_body_state: ReceivedBodyState::Start,
secure: false,
Expand Down
4 changes: 2 additions & 2 deletions http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ mod util;
mod body;
pub use body::Body;

mod state_set;
pub use state_set::StateSet;
pub use type_set;
pub use type_set::TypeSet;

mod headers;
pub use headers::{HeaderName, HeaderValue, HeaderValues, Headers, KnownHeaderName};
Expand Down
143 changes: 0 additions & 143 deletions http/src/state_set.rs

This file was deleted.

4 changes: 2 additions & 2 deletions http/src/synthetic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
after_send::AfterSend, http_config::DEFAULT_CONFIG, received_body::ReceivedBodyState,
transport::Transport, Conn, Headers, KnownHeaderName, Method, StateSet, Swansong, Version,
transport::Transport, Conn, Headers, KnownHeaderName, Method, Swansong, TypeSet, Version,
};
use futures_lite::io::{AsyncRead, AsyncWrite, Cursor, Result};
use std::{
Expand Down Expand Up @@ -145,7 +145,7 @@ impl Conn<Synthetic> {
method,
status: None,
version: Version::Http1_1,
state: StateSet::new(),
state: TypeSet::new(),
response_body: None,
buffer: Vec::with_capacity(DEFAULT_CONFIG.request_buffer_initial_len).into(),
request_body_state: ReceivedBodyState::Start,
Expand Down
8 changes: 4 additions & 4 deletions http/src/upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{received_body::read_buffered, Buffer, Conn, Headers, Method, StateSet, Swansong};
use crate::{received_body::read_buffered, Buffer, Conn, Headers, Method, Swansong, TypeSet};
use futures_lite::{AsyncRead, AsyncWrite};
use std::{
fmt::{self, Debug, Formatter},
Expand Down Expand Up @@ -31,7 +31,7 @@ pub struct Upgrade<Transport> {
/// The http request method
pub method: Method,
/// Any state that has been accumulated on the Conn before negotiating the upgrade
pub state: StateSet,
pub state: TypeSet,
/// The underlying io (often a `TcpStream` or similar)
#[async_write]
pub transport: Transport,
Expand Down Expand Up @@ -62,7 +62,7 @@ impl<Transport> Upgrade<Transport> {
method,
transport,
buffer,
state: StateSet::new(),
state: TypeSet::new(),
swansong: Swansong::new(),
peer_ip: None,
}
Expand Down Expand Up @@ -96,7 +96,7 @@ impl<Transport> Upgrade<Transport> {

/// any state that has been accumulated on the Conn before
/// negotiating the upgrade.
pub fn state(&self) -> &StateSet {
pub fn state(&self) -> &TypeSet {
&self.state
}

Expand Down
Loading

0 comments on commit 3d71146

Please sign in to comment.