Skip to content

Commit

Permalink
chore: cleanup and expose API
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAlcibiades committed Sep 11, 2024
1 parent 3f4374f commit be3ad7f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@ struct ErrorImpl {
/// Enum representing different kinds of errors that can occur.
/// Currently, only includes a Transport variant, but can be extended for more error types.
#[derive(Debug)]
pub(crate) enum Kind {
pub enum Kind {
Transport,
}

impl Error {
/// Creates a new Error with a specific kind.
pub(crate) fn new(kind: Kind) -> Self {
pub fn new(kind: Kind) -> Self {
Self {
inner: ErrorImpl { kind, source: None },
}
}

Check warning on line 33 in src/error.rs

View check run for this annotation

Codecov / codecov/patch

src/error.rs#L29-L33

Added lines #L29 - L33 were not covered by tests

/// Attaches a source error to this Error.
/// This method consumes self and returns a new Error, allowing for method chaining.
pub(crate) fn with(mut self, source: impl Into<Source>) -> Self {
pub fn with(mut self, source: impl Into<Source>) -> Self {
self.inner.source = Some(source.into());
self
}

Check warning on line 40 in src/error.rs

View check run for this annotation

Codecov / codecov/patch

src/error.rs#L37-L40

Added lines #L37 - L40 were not covered by tests

/// Creates a new Transport Error with the given source.
/// This is a convenience method combining new() and with().
pub(crate) fn from_source(source: impl Into<crate::Error>) -> Self {
pub fn from_source(source: impl Into<crate::Error>) -> Self {
Error::new(Kind::Transport).with(source)
}

Check warning on line 46 in src/error.rs

View check run for this annotation

Codecov / codecov/patch

src/error.rs#L44-L46

Added lines #L44 - L46 were not covered by tests

Expand Down
3 changes: 2 additions & 1 deletion src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use http_body::Body;
use hyper::body::Incoming;
use hyper::service::Service;
use hyper_util::{
rt::{TokioExecutor, TokioIo},
rt::TokioIo,
server::conn::auto::{Builder as HttpConnectionBuilder, HttpServerConnExec},
};
use tokio::io::{AsyncRead, AsyncWrite};
Expand Down Expand Up @@ -232,6 +232,7 @@ mod tests {
use bytes::Bytes;
use http_body_util::{BodyExt, Empty, Full};
use hyper::{body::Incoming, Request, Response, StatusCode};
use hyper_util::rt::TokioExecutor;
use hyper_util::service::TowerToHyperService;
use tokio::net::{TcpListener, TcpStream};
use tokio::sync::oneshot;
Expand Down
13 changes: 8 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
pub use error::{Error as TransportError, Kind as TransportErrorKind};
pub use http::serve_http_connection;
pub use http::serve_http_with_shutdown;
pub use tcp::serve_tcp_incoming;
pub use tls::load_certs;
pub use tls::load_private_key;
pub use tls::serve_tls_incoming;

mod error;
mod fuse;
mod http;
mod tcp;
mod tls;

pub use tcp::serve_tcp_incoming;
pub use tls::serve_tls_incoming;
pub use http::serve_http_with_shutdown;
pub use http::serve_http_connection;

pub(crate) type Error = Box<dyn std::error::Error + Send + Sync>;
3 changes: 1 addition & 2 deletions src/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,9 @@ mod tests {
use super::*;
use crate::tcp::serve_tcp_incoming;
use futures::StreamExt;
use rustls::pki_types::{CertificateDer, PrivateKeyDer, ServerName};
use rustls::pki_types::{CertificateDer, ServerName};
use rustls::{ClientConfig, ServerConfig};
use std::net::SocketAddr;
use std::pin::Pin;
use std::sync::Arc;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::net::{TcpListener, TcpStream};
Expand Down

0 comments on commit be3ad7f

Please sign in to comment.