chore(proto): crate formatting

This commit is contained in:
Jindřich Moravec 2023-12-23 01:28:30 +01:00
parent 505f59b354
commit a08376766c
18 changed files with 103 additions and 75 deletions

View file

@ -17,7 +17,10 @@ pub async fn do_client_handshake(
writer.flush().await?;
let auth = reader.read_proto().await?;
if !matches!(auth, BackendMessage::AuthenticationOk(AuthenticationOkData { status: 0 })) {
if !matches!(
auth,
BackendMessage::AuthenticationOk(AuthenticationOkData { status: 0 })
) {
return Err(ClientHandshakeError::UnexpectedAuthResponse(auth));
}
@ -32,4 +35,4 @@ pub async fn do_client_handshake(
}
HandshakeResponse::try_from(messages.as_slice())
}
}

View file

@ -1,9 +1,9 @@
use thiserror::Error;
use tokio::io;
use crate::message::backend::BackendMessage;
use crate::message::errors::ProtoDeserializeError;
use crate::reader::errors::{ProtoConsumeError, ProtoPeekError, ProtoReadError};
use crate::writer::errors::ProtoWriteError;
use thiserror::Error;
use tokio::io;
#[derive(Debug, Error)]
pub enum ClientHandshakeError {
@ -33,4 +33,4 @@ pub enum ServerHandshakeError {
Consume(#[from] ProtoConsumeError),
#[error("writing message to socket failed")]
Write(#[from] ProtoWriteError),
}
}

View file

@ -1,5 +1,5 @@
pub mod response;
pub mod request;
pub mod client;
pub mod errors;
pub mod request;
pub mod response;
pub mod server;
pub mod errors;

View file

@ -9,7 +9,10 @@ pub struct HandshakeRequest {
impl HandshakeRequest {
pub fn new(version: i32) -> Self {
Self { version, parameters: Vec::new() }
Self {
version,
parameters: Vec::new(),
}
}
pub fn parameter(mut self, key: &str, value: &str) -> Self {
@ -20,12 +23,18 @@ impl HandshakeRequest {
impl From<HandshakeRequest> for StartupMessageData {
fn from(request: HandshakeRequest) -> Self {
Self { version: request.version, params: request.parameters }
Self {
version: request.version,
params: request.parameters,
}
}
}
impl From<StartupMessageData> for HandshakeRequest {
fn from(data: StartupMessageData) -> Self {
Self { version: data.version, parameters: data.params }
Self {
version: data.version,
parameters: data.params,
}
}
}
}

View file

@ -1,10 +1,7 @@
use crate::handshake::errors::ServerHandshakeError;
use crate::handshake::request::HandshakeRequest;
use crate::handshake::response::HandshakeResponse;
use crate::message::backend::{
AuthenticationOkData, BackendMessage,
ReadyForQueryData,
};
use crate::message::backend::{AuthenticationOkData, BackendMessage, ReadyForQueryData};
use crate::message::special::{SpecialMessage, StartupMessageData};
use crate::reader::frontend::FrontendProtoReader;
use crate::writer::backend::BackendProtoWriter;