Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
7a0cf00cbc | |||
971556af64 | |||
f40c87aa8e | |||
b685d81e00 | |||
284ee73ffd |
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -294,7 +294,7 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lib"
|
name = "lib"
|
||||||
version = "1.3.2"
|
version = "1.3.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"derive",
|
"derive",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lib"
|
name = "lib"
|
||||||
version = "1.3.2"
|
version = "1.3.5"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Martin Berg Alstad"]
|
authors = ["Martin Berg Alstad"]
|
||||||
homepage = "emberal.github.io"
|
homepage = "emberal.github.io"
|
||||||
|
2
examples/multipart_file/Cargo.lock
generated
2
examples/multipart_file/Cargo.lock
generated
@ -286,7 +286,7 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lib"
|
name = "lib"
|
||||||
version = "1.3.2"
|
version = "1.3.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use std::net::IpAddr;
|
||||||
use {
|
use {
|
||||||
axum::{extract::Request, handler::Handler, Router, ServiceExt},
|
axum::{extract::Request, handler::Handler, Router, ServiceExt},
|
||||||
std::{io, net::Ipv4Addr, net::SocketAddr},
|
std::{io, net::Ipv4Addr, net::SocketAddr},
|
||||||
@ -26,7 +27,7 @@ macro_rules! create_app {
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct AppBuilder {
|
pub struct AppBuilder {
|
||||||
router: Router,
|
router: Router,
|
||||||
socket: Option<(Ipv4Addr, u16)>,
|
socket: Option<(IpAddr, u16)>,
|
||||||
cors: Option<CorsLayer>,
|
cors: Option<CorsLayer>,
|
||||||
normalize_path: Option<bool>,
|
normalize_path: Option<bool>,
|
||||||
tracing: Option<TraceLayer<HttpMakeClassifier>>,
|
tracing: Option<TraceLayer<HttpMakeClassifier>>,
|
||||||
@ -47,8 +48,18 @@ impl AppBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn socket(mut self, socket: impl Into<(Ipv4Addr, u16)>) -> Self {
|
pub fn socket<IP: Into<IpAddr>>(mut self, socket: impl Into<(IP, u16)>) -> Self {
|
||||||
self.socket = Some(socket.into());
|
let (ip, port) = socket.into();
|
||||||
|
self.socket = Some((ip.into(), port));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn port(mut self, port: u16) -> Self {
|
||||||
|
self.socket = if let Some((ip, _)) = self.socket {
|
||||||
|
Some((ip, port))
|
||||||
|
} else {
|
||||||
|
Some((Ipv4Addr::UNSPECIFIED.into(), port))
|
||||||
|
};
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +102,7 @@ impl AppBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn listener(&self) -> io::Result<TcpListener> {
|
async fn listener(&self) -> io::Result<TcpListener> {
|
||||||
let addr = SocketAddr::from(self.socket.unwrap_or((Ipv4Addr::UNSPECIFIED, 8000)));
|
let addr = SocketAddr::from(self.socket.unwrap_or((Ipv4Addr::UNSPECIFIED.into(), 8000)));
|
||||||
info!("Initializing server on: {addr}");
|
info!("Initializing server on: {addr}");
|
||||||
TcpListener::bind(&addr).await
|
TcpListener::bind(&addr).await
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,12 @@
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! router {
|
macro_rules! router {
|
||||||
($body:expr) => {
|
($body:expr) => {
|
||||||
pub(crate) fn router() -> axum::Router {
|
pub fn router() -> axum::Router {
|
||||||
$body
|
$body
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
($body:expr; $state:ty) => {
|
($body:expr; $state:ty) => {
|
||||||
pub(crate) fn router() -> axum::Router<$state> {
|
pub fn router() -> axum::Router<$state> {
|
||||||
$body
|
$body
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,7 @@ use {
|
|||||||
/// - Returns: A parser that trims leading and trailing whitespace from the input and then runs the value from the inner parser
|
/// - Returns: A parser that trims leading and trailing whitespace from the input and then runs the value from the inner parser
|
||||||
pub fn trim<'a, Parser, R>(inner: Parser) -> impl FnMut(&'a str) -> IResult<&'a str, R>
|
pub fn trim<'a, Parser, R>(inner: Parser) -> impl FnMut(&'a str) -> IResult<&'a str, R>
|
||||||
where
|
where
|
||||||
Parser: Fn(&'a str) -> IResult<&'a str, R>,
|
Parser: FnMut(&'a str) -> IResult<&'a str, R>,
|
||||||
{
|
{
|
||||||
delimited(multispace0, inner, multispace0)
|
delimited(multispace0, inner, multispace0)
|
||||||
}
|
}
|
||||||
@ -29,8 +29,9 @@ where
|
|||||||
/// - Returns: A parser that parses a parenthesized expression
|
/// - Returns: A parser that parses a parenthesized expression
|
||||||
pub fn parenthesized<'a, Parser, R>(inner: Parser) -> impl FnMut(&'a str) -> IResult<&'a str, R>
|
pub fn parenthesized<'a, Parser, R>(inner: Parser) -> impl FnMut(&'a str) -> IResult<&'a str, R>
|
||||||
where
|
where
|
||||||
Parser: Fn(&'a str) -> IResult<&'a str, R>,
|
Parser: FnMut(&'a str) -> IResult<&'a str, R>,
|
||||||
{
|
{
|
||||||
|
// TODO move trim out of here
|
||||||
delimited(char('('), trim(inner), char(')'))
|
delimited(char('('), trim(inner), char(')'))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,16 +50,15 @@ where
|
|||||||
|
|
||||||
pub fn exhausted<'a, Parser, R>(inner: Parser) -> impl FnMut(&'a str) -> IResult<&'a str, R>
|
pub fn exhausted<'a, Parser, R>(inner: Parser) -> impl FnMut(&'a str) -> IResult<&'a str, R>
|
||||||
where
|
where
|
||||||
Parser: Fn(&'a str) -> IResult<&'a str, R>,
|
Parser: FnMut(&'a str) -> IResult<&'a str, R>,
|
||||||
{
|
{
|
||||||
terminated(inner, eof)
|
terminated(inner, eof)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use nom::bytes::streaming::take_while;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use nom::{bytes::complete::take_while, sequence::tuple};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_trim_both_sides() {
|
fn test_trim_both_sides() {
|
||||||
@ -154,4 +154,16 @@ mod tests {
|
|||||||
let input = "test ";
|
let input = "test ";
|
||||||
assert!(exhausted(take_where(4, |c: char| c.is_ascii_alphabetic()))(input).is_err());
|
assert!(exhausted(take_where(4, |c: char| c.is_ascii_alphabetic()))(input).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_exhausted_tuple() {
|
||||||
|
let input = "test";
|
||||||
|
let (remaining, result) = exhausted(tuple((
|
||||||
|
take_where(3, |c: char| c.is_ascii_alphabetic()),
|
||||||
|
take_while(|c: char| c.is_ascii_alphabetic()),
|
||||||
|
)))(input)
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(remaining, "");
|
||||||
|
assert_eq!(result, ("tes", "t"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user