Skip to content

Commit

Permalink
Merge pull request #279 from c410-f3r/misc
Browse files Browse the repository at this point in the history
wtx-macros-0.4.0
  • Loading branch information
c410-f3r authored Nov 28, 2024
2 parents 0378eff + c47bef8 commit 072b504
Show file tree
Hide file tree
Showing 49 changed files with 158 additions and 258 deletions.
181 changes: 35 additions & 146 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion wtx-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ license = "MIT"
name = "wtx-macros"
readme = "README.md"
repository = "https://github.com/c410-f3r/wtx"
version = "0.3.0"
version = "0.4.0"

[package.metadata.docs.rs]
all-features = true
6 changes: 3 additions & 3 deletions wtx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ chrono = { default-features = false, optional = true, version = "0.4" }
cl-aux = { default-features = false, optional = true, features = ["alloc"], version = "5.0" }
crypto-common = { default-features = false, optional = true, version = "0.1" }
digest = { default-features = false, features = ["mac"], optional = true, version = "0.10" }
embassy-net = { default-features = false, features = ["tcp"], optional = true, version = "0.4" }
embassy-net = { default-features = false, features = ["tcp"], optional = true, version = "0.5" }
embedded-io-async = { default-features = false, optional = true, version = "0.6" }
embedded-tls = { default-features = false, optional = true, git = "https://github.com/drogue-iot/embedded-tls" }
embedded-tls = { default-features = false, optional = true, version = "0.17" }
fastrand = { default-features = false, optional = true, version = "2.0" }
flate2 = { default-features = false, features = ["zlib-rs"], optional = true, version = "1.0" }
foldhash = { default-features = false, optional = true, version = "0.1" }
Expand Down Expand Up @@ -72,7 +72,7 @@ http-session = ["chrono/serde", "http-cookie-secure", "serde_json"]
http2 = ["foldhash", "hashbrown", "http"]
httparse = ["dep:httparse"]
memchr = ["dep:memchr"]
nightly = ["hashbrown?/nightly"]
nightly = [] #FIXME(STABLE): "hashbrown?/nightly"
optimization = ["memchr", "simdutf8"]
pool = []
portable-atomic-util = ["portable-atomic", "dep:portable-atomic-util"]
Expand Down
3 changes: 1 addition & 2 deletions wtx/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod from_records;
mod json;
mod misc;
mod record;
mod record_values;
pub(crate) mod record_values;
mod records;
#[cfg(feature = "schema-manager")]
pub mod schema_manager;
Expand All @@ -30,7 +30,6 @@ pub use from_records::FromRecords;
pub use json::Json;
pub use misc::seek_related_entities;
pub use record::Record;
pub(crate) use record_values::encode;
pub use record_values::RecordValues;
pub use records::Records;
pub use stmt_cmd::StmtCmd;
Expand Down
5 changes: 3 additions & 2 deletions wtx/src/database/client/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ where
const TY: DatabaseTy = DatabaseTy::Postgres;

type DecodeValue<'exec> = DecodeValue<'exec>;
type EncodeValue<'buffer, 'tmp> = EncodeValue<'buffer, 'tmp>
type EncodeValue<'buffer, 'tmp>
= EncodeValue<'buffer, 'tmp>
where
'buffer: 'tmp;
type Error = E;
Expand All @@ -75,7 +76,7 @@ impl<E> Default for Postgres<E> {

#[cfg(test)]
mod tests {
use crate::database::client::postgres::{statements::Column, Ty};
use crate::database::client::postgres::{statements::column::Column, Ty};

pub(crate) fn column0() -> Column {
Column::new("a".try_into().unwrap(), Ty::VarcharArray)
Expand Down
3 changes: 2 additions & 1 deletion wtx/src/database/client/postgres/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ where
S: Stream,
{
type Database = Postgres<E>;
type TransactionManager<'tm> = TransactionManager<'tm, E, EB, S>
type TransactionManager<'tm>
= TransactionManager<'tm, E, EB, S>
where
Self: 'tm;

Expand Down
4 changes: 2 additions & 2 deletions wtx/src/database/client/postgres/executor/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::{
Identifier,
},
misc::{
bytes_split1, from_utf8_basic, ArrayVector, ConnectionState, FilledBufferWriter, LeaseMut,
PartitionedFilledBuffer, Rng, Stream, Vector,
bytes_split1, from_utf8_basic, partitioned_filled_buffer::PartitionedFilledBuffer, ArrayVector,
ConnectionState, FilledBufferWriter, LeaseMut, Rng, Stream, Vector,
},
};
use base64::prelude::{Engine as _, BASE64_STANDARD};
Expand Down
6 changes: 3 additions & 3 deletions wtx/src/database/client/postgres/executor/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use crate::{
client::postgres::{
executor::commons::FetchWithStmtCommons,
message::{Message, MessageTy},
statements::Statement,
statements::statement::Statement,
Executor, ExecutorBuffer, Postgres, PostgresError, Record,
},
RecordValues,
},
misc::{
ConnectionState, LeaseMut, PartitionedFilledBuffer, Stream, Usize, Vector, _read_header,
_read_payload,
partitioned_filled_buffer::PartitionedFilledBuffer, ConnectionState, LeaseMut, Stream, Usize,
Vector, _read_header, _read_payload,
},
};
use core::ops::Range;
Expand Down
7 changes: 5 additions & 2 deletions wtx/src/database/client/postgres/executor/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ use crate::{
message::MessageTy,
msg_field::MsgField,
protocol::{bind, describe, execute, parse, sync},
statements::{Column, Statement, StatementsMisc},
statements::{column::Column, statement::Statement, statements_misc::StatementsMisc},
ty::Ty,
Executor, Postgres, PostgresError, Statements,
},
RecordValues, StmtCmd,
},
misc::{ArrayString, FilledBufferWriter, LeaseMut, PartitionedFilledBuffer, Stream},
misc::{
partitioned_filled_buffer::PartitionedFilledBuffer, ArrayString, FilledBufferWriter, LeaseMut,
Stream,
},
};

impl<E, EB, S> Executor<E, EB, S>
Expand Down
2 changes: 1 addition & 1 deletion wtx/src/database/client/postgres/executor_buffer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
database::{client::postgres::Statements, Identifier},
misc::{Lease, LeaseMut, PartitionedFilledBuffer, Rng, Vector},
misc::{partitioned_filled_buffer::PartitionedFilledBuffer, Lease, LeaseMut, Rng, Vector},
};
use core::ops::Range;
use hashbrown::HashMap;
Expand Down
4 changes: 3 additions & 1 deletion wtx/src/database/client/postgres/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::{
database::{
client::postgres::{statements::Statement, Config, EncodeValue, Oid, Postgres, PostgresError},
client::postgres::{
statements::statement::Statement, Config, EncodeValue, Oid, Postgres, PostgresError,
},
RecordValues,
},
misc::{FilledBufferWriter, Vector},
Expand Down
4 changes: 2 additions & 2 deletions wtx/src/database/client/postgres/record.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
database::{
client::postgres::{statements::Statement, DecodeValue, Postgres, PostgresError},
client::postgres::{statements::statement::Statement, DecodeValue, Postgres, PostgresError},
Database, ValueIdent,
},
misc::{Vector, _unlikely_dflt, _unlikely_elem},
Expand Down Expand Up @@ -176,7 +176,7 @@ mod tests {
use crate::{
database::{
client::postgres::{
statements::Statement,
statements::statement::Statement,
tests::{column0, column1, column2},
DecodeValue, Record, Ty,
},
Expand Down
4 changes: 2 additions & 2 deletions wtx/src/database/client/postgres/records.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::database::client::postgres::{statements::Statement, Postgres, Record};
use crate::database::client::postgres::{statements::statement::Statement, Postgres, Record};
use core::{marker::PhantomData, ops::Range};

/// Records
Expand Down Expand Up @@ -89,7 +89,7 @@ mod tests {
use crate::{
database::{
client::postgres::{
statements::Statement,
statements::statement::Statement,
tests::{column0, column1, column2},
DecodeValue, Record, Records, Ty,
},
Expand Down
26 changes: 11 additions & 15 deletions wtx/src/database/client/postgres/statements.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
mod column;
mod statement;
mod statement_builder;
mod statements_misc;
pub(crate) mod column;
pub(crate) mod statement;
pub(crate) mod statement_builder;
pub(crate) mod statements_misc;

use crate::{
database::client::postgres::ty::Ty,
misc::{BlocksDeque, Rng, _random_state},
};
pub(crate) use column::Column;
use foldhash::fast::FixedState;
use hashbrown::HashMap;
pub(crate) use statement::Statement;
pub(crate) use statement_builder::StatementBuilder;
pub(crate) use statements_misc::StatementsMisc;

/// Statements
#[derive(Debug)]
pub struct Statements {
max_stmts: usize,
rs: FixedState,
stmts: BlocksDeque<(Column, Ty), StatementsMisc>,
stmts: BlocksDeque<(column::Column, Ty), statements_misc::StatementsMisc>,
stmts_indcs: HashMap<u64, usize>,
}

Expand Down Expand Up @@ -56,7 +52,7 @@ impl Statements {
}

#[inline]
pub(crate) fn builder(&mut self) -> StatementBuilder<'_> {
pub(crate) fn builder(&mut self) -> statement_builder::StatementBuilder<'_> {
if self.stmts.blocks_len() >= self.max_stmts {
let to_remove = (self.max_stmts / 2).max(1);
for _ in 0..to_remove {
Expand All @@ -70,7 +66,7 @@ impl Statements {
true
})
}
StatementBuilder::new(&mut self.stmts, &mut self.stmts_indcs)
statement_builder::StatementBuilder::new(&mut self.stmts, &mut self.stmts_indcs)
}

#[inline]
Expand All @@ -81,13 +77,13 @@ impl Statements {
}

#[inline]
pub(crate) fn get_by_idx(&self, idx: usize) -> Option<Statement<'_>> {
pub(crate) fn get_by_idx(&self, idx: usize) -> Option<statement::Statement<'_>> {
let stmt = self.stmts.get(idx)?;
Some(Statement::new(stmt.misc.columns_len, stmt.misc.types_len, stmt.data))
Some(statement::Statement::new(stmt.misc.columns_len, stmt.misc.types_len, stmt.data))
}

#[inline]
pub(crate) fn get_by_stmt_hash(&self, stmt_hash: u64) -> Option<Statement<'_>> {
pub(crate) fn get_by_stmt_hash(&self, stmt_hash: u64) -> Option<statement::Statement<'_>> {
self.get_by_idx(*self.stmts_indcs.get(&stmt_hash)?)
}

Expand All @@ -101,7 +97,7 @@ impl Statements {
mod tests {
use crate::{
database::client::postgres::{
statements::StatementsMisc,
statements::statements_misc::StatementsMisc,
tests::{column0, column1, column2, column3},
ty::Ty,
Statements,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
database::{
client::postgres::{
statements::{column::Column, StatementsMisc},
statements::{column::Column, statements_misc::StatementsMisc},
Ty,
},
Identifier,
Expand Down
2 changes: 1 addition & 1 deletion wtx/src/database/client/postgres/tys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ macro_rules! test {
#[cfg(test)]
#[test]
fn $name() {
let vec = &mut crate::misc::FilledBuffer::_new();
let vec = &mut crate::misc::filled_buffer::FilledBuffer::_new();
let mut fbw = crate::misc::FilledBufferWriter::new(0, vec);
let mut ev = EncodeValue::new(&mut fbw);
let instance: $ty = $instance;
Expand Down
8 changes: 3 additions & 5 deletions wtx/src/http/cookie.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
mod cookie_bytes;
pub(crate) mod cookie_bytes;
mod cookie_error;
mod cookie_generic;
pub(crate) mod cookie_generic;
mod same_site;

use crate::misc::{ArrayVector, Rng, Vector, _shift_copyable_chunks};
pub(crate) use cookie_bytes::CookieBytes;
use crate::misc::{mem_transfer::_shift_copyable_chunks, ArrayVector, Rng, Vector};
pub use cookie_error::CookieError;
pub(crate) use cookie_generic::CookieGeneric;
use core::str;
pub use same_site::SameSite;

Expand Down
24 changes: 13 additions & 11 deletions wtx/src/http/req_res_data.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::{
http::Headers,
misc::{Lease, LeaseMut, Uri, UriString, _EMPTY_URI_STRING},
misc::{Lease, LeaseMut, Uri, UriString},
};
use alloc::boxed::Box;
use alloc::{boxed::Box, string::String};

static EMPTY_URI_STRING: UriString = UriString::_empty(String::new());

/// Groups the elements of an HTTP request/response.
pub trait ReqResData {
Expand Down Expand Up @@ -78,7 +80,7 @@ impl ReqResData for &[u8] {

#[inline]
fn uri(&self) -> &UriString {
&_EMPTY_URI_STRING
&EMPTY_URI_STRING
}
}

Expand All @@ -97,7 +99,7 @@ impl<const N: usize> ReqResData for [u8; N] {

#[inline]
fn uri(&self) -> &UriString {
&_EMPTY_URI_STRING
&EMPTY_URI_STRING
}
}

Expand All @@ -116,7 +118,7 @@ impl ReqResData for () {

#[inline]
fn uri(&self) -> &UriString {
&_EMPTY_URI_STRING
&EMPTY_URI_STRING
}
}

Expand All @@ -138,7 +140,7 @@ where

#[inline]
fn uri(&self) -> &UriString {
&_EMPTY_URI_STRING
&EMPTY_URI_STRING
}
}

Expand All @@ -160,7 +162,7 @@ where

#[inline]
fn uri(&self) -> &UriString {
&_EMPTY_URI_STRING
&EMPTY_URI_STRING
}
}

Expand All @@ -179,7 +181,7 @@ impl ReqResData for Headers {

#[inline]
fn uri(&self) -> &UriString {
&_EMPTY_URI_STRING
&EMPTY_URI_STRING
}
}

Expand All @@ -201,7 +203,7 @@ where

#[inline]
fn uri(&self) -> &UriString {
&_EMPTY_URI_STRING
&EMPTY_URI_STRING
}
}

Expand Down Expand Up @@ -282,7 +284,7 @@ impl ReqResDataMut for Headers {

#[inline]
fn parts_mut(&mut self) -> (&mut Self::Body, &mut Headers, &UriString) {
(&mut [], self, &_EMPTY_URI_STRING)
(&mut [], self, &EMPTY_URI_STRING)
}
}

Expand All @@ -295,6 +297,6 @@ where

#[inline]
fn parts_mut(&mut self) -> (&mut Self::Body, &mut Headers, &UriString) {
(&mut self.0, self.1.lease_mut(), &_EMPTY_URI_STRING)
(&mut self.0, self.1.lease_mut(), &EMPTY_URI_STRING)
}
}
2 changes: 1 addition & 1 deletion wtx/src/http/session/session_decoder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
http::{
cookie::{decrypt, CookieBytes},
cookie::{cookie_bytes::CookieBytes, decrypt},
server_framework::Middleware,
KnownHeaderName, ReqResBuffer, Request, Response, SessionError, SessionManager,
SessionManagerInner, SessionState, SessionStore, StatusCode,
Expand Down
2 changes: 1 addition & 1 deletion wtx/src/http/session/session_manager.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
http::{
cookie::{encrypt, CookieGeneric},
cookie::{cookie_generic::CookieGeneric, encrypt},
session::SessionKey,
Header, KnownHeaderName, ReqResBuffer, ReqResDataMut, SessionManagerBuilder, SessionState,
SessionStore,
Expand Down
2 changes: 1 addition & 1 deletion wtx/src/http/session/session_manager_builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
http::{
cookie::{CookieGeneric, SameSite},
cookie::{cookie_generic::CookieGeneric, SameSite},
session::{SessionKey, SessionManagerInner},
SessionManager, SessionStore,
},
Expand Down
Loading

0 comments on commit 072b504

Please sign in to comment.