formatting!

This commit is contained in:
nora 2022-03-10 19:18:26 +01:00
parent 770762b920
commit cae9683bd4
33 changed files with 147 additions and 87 deletions

View file

@ -1,3 +1,3 @@
reorder_imports = true
imports_granularity = "Crate"
newline_style = "Unix"
group_imports = "StdExternalCrate"

View file

@ -1,15 +1,21 @@
use crate::{consumer::Consumer, methods, methods::Method, newtype_id, GlobalData, Queue};
use bytes::Bytes;
use parking_lot::Mutex;
use smallvec::SmallVec;
use std::{
collections::HashMap,
fmt::{Display, Formatter},
net::SocketAddr,
sync::Arc,
};
use bytes::Bytes;
use parking_lot::Mutex;
use smallvec::SmallVec;
use tokio::sync::mpsc;
use crate::{
consumer::Consumer,
methods::{self, Method},
newtype_id, GlobalData, Queue,
};
newtype_id!(pub ConnectionId);
newtype_id!(pub ChannelId);

View file

@ -8,19 +8,21 @@ pub mod message;
pub mod methods;
pub mod queue;
use crate::{
connection::{Channel, Connection},
queue::{Queue, QueueName},
};
use connection::{ChannelId, ConnectionId};
use parking_lot::Mutex;
use std::{
collections::HashMap,
fmt::{Debug, Formatter},
sync::Arc,
};
use connection::{ChannelId, ConnectionId};
use parking_lot::Mutex;
use uuid::Uuid;
use crate::{
connection::{Channel, Connection},
queue::{Queue, QueueName},
};
#[derive(Clone)]
pub struct GlobalData {
inner: Arc<Mutex<GlobalDataInner>>,

View file

@ -1,7 +1,9 @@
use crate::{connection::ContentHeader, newtype_id};
use std::sync::Arc;
use bytes::Bytes;
use smallvec::SmallVec;
use std::sync::Arc;
use crate::{connection::ContentHeader, newtype_id};
pub type Message = Arc<MessageInner>;

View file

@ -1,17 +1,19 @@
use crate::{
consumer::{Consumer, ConsumerId},
message::Message,
newtype, newtype_id, ChannelId,
};
use parking_lot::Mutex;
use std::{
borrow::Borrow,
collections::HashMap,
fmt::{Debug, Display, Formatter},
sync::{atomic::AtomicUsize, Arc},
};
use parking_lot::Mutex;
use tokio::sync::mpsc;
use crate::{
consumer::{Consumer, ConsumerId},
message::Message,
newtype, newtype_id, ChannelId,
};
pub type Queue = Arc<QueueInner>;
#[derive(Debug)]

View file

@ -1,10 +1,11 @@
use anyhow::{ensure, Context, Result};
use std::{
env,
fs::File,
path::{Path, PathBuf},
process::Command,
};
use anyhow::{ensure, Context, Result};
use walkdir::WalkDir;
use zip::{write::FileOptions, ZipWriter};

View file

@ -1,8 +1,3 @@
use axum::{
body::Body,
http::{header, Request, Response, StatusCode},
};
use mime_guess::mime;
use std::{
collections::HashMap,
fmt::{Debug, Formatter},
@ -11,6 +6,12 @@ use std::{
path::Path,
task::{Context, Poll},
};
use axum::{
body::Body,
http::{header, Request, Response, StatusCode},
};
use mime_guess::mime;
use tracing::trace;
use zip::ZipArchive;

View file

@ -2,7 +2,6 @@
mod archive;
use crate::archive::StaticFileService;
use amqp_core::GlobalData;
use axum::{
http::{Method, StatusCode},
@ -14,6 +13,8 @@ use serde::Serialize;
use tower_http::cors::{Any, CorsLayer};
use tracing::{error, info};
use crate::archive::StaticFileService;
const DATA_ZIP: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/frontend.zip"));
pub async fn start_dashboard(global_data: GlobalData) {

View file

@ -1,4 +1,5 @@
use crate::Result;
use std::sync::Arc;
use amqp_core::{
amqp_todo,
connection::Channel,
@ -6,9 +7,10 @@ use amqp_core::{
error::ChannelException,
methods::{BasicConsume, BasicConsumeOk, Method},
};
use std::sync::Arc;
use tracing::info;
use crate::Result;
pub fn consume(channel: Channel, basic_consume: BasicConsume) -> Result<Method> {
let BasicConsume {
queue: queue_name,

View file

@ -2,10 +2,11 @@ mod consume;
mod publish;
mod queue;
use crate::Result;
use amqp_core::{amqp_todo, connection::Channel, message::Message, methods::Method};
use tracing::info;
use crate::Result;
pub fn handle_basic_publish(channel_handle: Channel, message: Message) -> Result<()> {
publish::publish(channel_handle, message)
}

View file

@ -1,4 +1,3 @@
use crate::Result;
use amqp_core::{
amqp_todo,
connection::Channel,
@ -8,6 +7,8 @@ use amqp_core::{
};
use tracing::{debug, error};
use crate::Result;
pub fn publish(channel_handle: Channel, message: Message) -> Result<()> {
debug!(?message, "Publishing message");

View file

@ -1,4 +1,5 @@
use crate::{queue_worker::QueueTask, Result};
use std::sync::{atomic::AtomicUsize, Arc};
use amqp_core::{
amqp_todo,
connection::Channel,
@ -7,9 +8,10 @@ use amqp_core::{
GlobalData,
};
use parking_lot::Mutex;
use std::sync::{atomic::AtomicUsize, Arc};
use tokio::sync::mpsc;
use crate::{queue_worker::QueueTask, Result};
pub fn declare(channel: Channel, queue_declare: QueueDeclare) -> Result<Method> {
let QueueDeclare {
queue: queue_name,

View file

@ -1,3 +1,5 @@
use std::borrow::Borrow;
use amqp_core::{
connection::ConnectionEvent,
consumer::Consumer,
@ -6,7 +8,6 @@ use amqp_core::{
queue::{Queue, QueueEvent, QueueEventReceiver},
GlobalData,
};
use std::borrow::Borrow;
use tracing::info;
#[derive(Debug)]

View file

@ -1,5 +1,7 @@
use amqp_core::methods::Method;
use amqp_transport::methods::{self, RandomMethod};
use amqp_transport::methods::{
RandomMethod, {self},
};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rand::SeedableRng;

View file

@ -1,9 +1,7 @@
use crate::{
error::{ConException, ProtocolError, Result, TransError},
frame,
frame::{parse_content_header, Frame, FrameType, MaxFrameSize},
methods, sasl,
use std::{
cmp::Ordering, collections::HashMap, net::SocketAddr, pin::Pin, sync::Arc, time::Duration,
};
use amqp_core::{
connection::{
Channel, ChannelInner, ChannelNum, ConEventReceiver, ConEventSender, Connection,
@ -20,9 +18,6 @@ use amqp_core::{
use anyhow::{anyhow, Context};
use bytes::Bytes;
use smallvec::SmallVec;
use std::{
cmp::Ordering, collections::HashMap, net::SocketAddr, pin::Pin, sync::Arc, time::Duration,
};
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
net::TcpStream,
@ -30,6 +25,12 @@ use tokio::{
};
use tracing::{debug, error, info, trace, warn};
use crate::{
error::{ConException, ProtocolError, Result, TransError},
frame::{self, parse_content_header, Frame, FrameType, MaxFrameSize},
methods, sasl,
};
fn ensure_conn(condition: bool) -> Result<()> {
if condition {
Ok(())

View file

@ -1,14 +1,16 @@
use crate::error::{ConException, ProtocolError, Result};
use amqp_core::connection::{ChannelNum, ContentHeader};
use anyhow::Context;
use bytes::Bytes;
use std::{
fmt::{Debug, Formatter},
num::NonZeroUsize,
};
use amqp_core::connection::{ChannelNum, ContentHeader};
use anyhow::Context;
use bytes::Bytes;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tracing::trace;
use crate::error::{ConException, ProtocolError, Result};
const REQUIRED_FRAME_END: u8 = 0xCE;
mod frame_type {
@ -37,20 +39,23 @@ pub enum FrameType {
}
mod content_header_parse {
use crate::{
error::TransError,
methods::parse_helper::{octet, shortstr, table, timestamp},
};
use amqp_core::{
connection::ContentHeader,
methods,
methods::FieldValue::{FieldTable, ShortShortUInt, ShortString, Timestamp},
methods::{
self,
FieldValue::{FieldTable, ShortShortUInt, ShortString, Timestamp},
},
};
use nom::number::{
complete::{u16, u64},
Endianness::Big,
};
use crate::{
error::TransError,
methods::parse_helper::{octet, shortstr, table, timestamp},
};
type IResult<'a, T> = nom::IResult<&'a [u8], T, TransError>;
pub fn basic_properties(flags: u16, input: &[u8]) -> IResult<'_, methods::Table> {
@ -133,10 +138,8 @@ pub fn parse_content_header(input: &[u8]) -> Result<ContentHeader> {
}
mod content_header_write {
use crate::{
error::Result,
methods::write_helper::{longlong, octet, short, shortstr, table, timestamp},
};
use std::io::Write;
use amqp_core::{
connection::ContentHeader,
methods::{
@ -144,7 +147,11 @@ mod content_header_write {
Table,
},
};
use std::io::Write;
use crate::{
error::Result,
methods::write_helper::{longlong, octet, short, shortstr, table, timestamp},
};
pub fn write_content_header<W: Write>(buf: &mut W, header: &ContentHeader) -> Result<()> {
short(&header.class_id, buf)?;
@ -325,9 +332,10 @@ fn parse_frame_type(kind: u8, channel: ChannelNum) -> Result<FrameType> {
#[cfg(test)]
mod tests {
use crate::frame::{ChannelNum, Frame, FrameType, MaxFrameSize};
use bytes::Bytes;
use crate::frame::{ChannelNum, Frame, FrameType, MaxFrameSize};
#[tokio::test]
async fn read_small_body() {
let mut bytes: &[u8] = &[

View file

@ -10,13 +10,15 @@ mod tests;
// TODO: handle big types
use crate::connection::TransportConnection;
use std::{future::Future, net::SocketAddr};
use amqp_core::{connection::ConnectionEvent, queue::QueueEvent, GlobalData};
use anyhow::Context;
use std::{future::Future, net::SocketAddr};
use tokio::{net, net::TcpStream, select};
use tracing::{info, info_span, Instrument};
use crate::connection::TransportConnection;
pub async fn do_thing_i_guess(
global_data: GlobalData,
terminate: impl Future + Send,

View file

@ -2,12 +2,13 @@
// This file has been generated by `xtask/src/codegen`. Do not edit it manually.
pub mod parse {
use crate::{error::TransError, methods::parse_helper::*};
use amqp_core::methods::*;
use nom::{branch::alt, bytes::complete::tag};
use once_cell::sync::Lazy;
use regex::Regex;
use crate::{error::TransError, methods::parse_helper::*};
pub type IResult<'a, T> = nom::IResult<&'a [u8], T, TransError>;
pub fn parse_method(input: &[u8]) -> Result<(&[u8], Method), nom::Err<TransError>> {
@ -886,10 +887,12 @@ pub mod parse {
}
}
pub mod write {
use crate::{error::TransError, methods::write_helper::*};
use amqp_core::methods::*;
use std::io::Write;
use amqp_core::methods::*;
use crate::{error::TransError, methods::write_helper::*};
pub fn write_method<W: Write>(method: &Method, mut writer: W) -> Result<(), TransError> {
match method {
Method::ConnectionStart(ConnectionStart {
@ -1303,10 +1306,11 @@ pub mod write {
}
mod random {
use crate::methods::RandomMethod;
use amqp_core::methods::*;
use rand::Rng;
use crate::methods::RandomMethod;
impl<R: Rng> RandomMethod<R> for Method {
#[allow(unused_variables)]
fn random(rng: &mut R) -> Self {

View file

@ -1,10 +1,11 @@
use crate::error::TransError;
use amqp_core::{
error::ConException,
methods::{FieldValue, Method, Table},
};
use rand::Rng;
use crate::error::TransError;
mod generated;
pub mod parse_helper;
#[cfg(test)]

View file

@ -1,4 +1,3 @@
use crate::{error::TransError, methods::generated::parse::IResult};
use amqp_core::{
error::{ConException, ProtocolError},
methods::{
@ -18,6 +17,8 @@ use nom::{
Err,
};
use crate::{error::TransError, methods::generated::parse::IResult};
impl<T> nom::error::ParseError<T> for TransError {
fn from_error_kind(_input: T, _kind: ErrorKind) -> Self {
ConException::SyntaxError(vec![]).into()

View file

@ -1,10 +1,12 @@
// create random methods to test the ser/de code together. if they diverge, we have a bug
// this is not perfect, if they both have the same bug it won't be found, but that's an ok tradeoff
use crate::methods::{FieldValue, Method, RandomMethod};
use rand::SeedableRng;
use std::collections::HashMap;
use rand::SeedableRng;
use crate::methods::{FieldValue, Method, RandomMethod};
#[test]
fn pack_few_bits() {
let bits = [true, false, true];

View file

@ -1,7 +1,9 @@
use crate::{error::TransError, methods::FieldValue};
use std::io::Write;
use amqp_core::methods::{Bit, Long, Longlong, Longstr, Octet, Short, Shortstr, Table, Timestamp};
use anyhow::Context;
use std::io::Write;
use crate::{error::TransError, methods::FieldValue};
pub fn octet<W: Write>(value: &Octet, writer: &mut W) -> Result<(), TransError> {
writer.write_all(&[*value])?;

View file

@ -2,9 +2,10 @@
//!
//! Currently only supports PLAIN (see [RFC 4616](https://datatracker.ietf.org/doc/html/rfc4616))
use crate::error::Result;
use amqp_core::error::ConException;
use crate::error::Result;
pub struct PlainUser {
pub authorization_identity: String,
pub authentication_identity: String,

View file

@ -1,9 +1,11 @@
use crate::{frame, frame::FrameType, methods};
use std::collections::HashMap;
use amqp_core::{
connection::ChannelNum,
methods::{ConnectionStart, ConnectionStartOk, FieldValue, Method},
};
use std::collections::HashMap;
use crate::{frame, frame::FrameType, methods};
#[tokio::test]
async fn write_start_ok_frame() {

View file

@ -1,8 +1,9 @@
#![warn(rust_2018_idioms)]
use std::str::FromStr;
use anyhow::Result;
use clap::Parser;
use std::str::FromStr;
use tracing::info;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry};

View file

@ -1,7 +1,9 @@
use crate::{project_root, yarn_install};
use anyhow::ensure;
use std::process::Command;
use anyhow::ensure;
use crate::{project_root, yarn_install};
pub fn main() -> anyhow::Result<()> {
println!("$ cargo fmt --check");
let status = Command::new("cargo")

View file

@ -4,8 +4,6 @@ mod parser;
mod random;
mod write;
use anyhow::{bail, Context};
use heck::ToUpperCamelCase;
use std::{
fs,
fs::File,
@ -15,6 +13,9 @@ use std::{
process::Command,
str::FromStr,
};
use anyhow::{bail, Context};
use heck::ToUpperCamelCase;
use strong_xml::XmlRead;
#[derive(Debug, XmlRead)]

View file

@ -1,8 +1,9 @@
use super::{Amqp, Assert, Class, Domain, Method};
use crate::codegen::Codegen;
use heck::{ToSnakeCase, ToUpperCamelCase};
use itertools::Itertools;
use super::{Amqp, Assert, Class, Domain, Method};
use crate::codegen::Codegen;
fn method_function_name(class_name: &str) -> impl Fn(&Method) -> String + '_ {
move |method| {
let method_name = method.name.to_snake_case();

View file

@ -1,6 +1,7 @@
use crate::codegen::{Amqp, Codegen};
use heck::ToUpperCamelCase;
use crate::codegen::{Amqp, Codegen};
impl Codegen {
pub fn codegen_random(&mut self, amqp: &Amqp) {
writeln!(

View file

@ -1,6 +1,7 @@
use crate::codegen::{Amqp, Codegen};
use heck::ToUpperCamelCase;
use crate::codegen::{Amqp, Codegen};
impl Codegen {
pub fn codegen_write(&mut self, amqp: &Amqp) {
writeln!(

View file

@ -1,7 +1,9 @@
use crate::{project_root, yarn_install};
use anyhow::ensure;
use std::process::Command;
use anyhow::ensure;
use crate::{project_root, yarn_install};
pub fn main() -> anyhow::Result<()> {
println!("$ cargo fmt");
let status = Command::new("cargo")

View file

@ -1,9 +1,10 @@
use anyhow::{ensure, Context, Result};
use std::{
path::{Path, PathBuf},
process::Command,
};
use anyhow::{ensure, Context, Result};
mod check_fmt;
mod codegen;
mod fmt;

View file

@ -1,7 +1,9 @@
use crate::{project_root, yarn_install};
use anyhow::{ensure, Context, Result};
use std::{path::Path, process::Command, thread::sleep, time::Duration};
use anyhow::{ensure, Context, Result};
use crate::{project_root, yarn_install};
pub fn main() -> Result<()> {
let project_root = project_root();
let test_js_root = project_root.join("test-js");