Skip to content

Commit

Permalink
feat: add viz-smol
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Jan 12, 2024
1 parent 0d01663 commit 39066c8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions viz-core/src/response.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use http_body_util::Full;

use crate::{header, Body, BoxError, Bytes, Error, Future, Response, Result, StatusCode};
use crate::{header, Body, BoxError, Bytes, Response, Result, StatusCode};

/// The [`Response`] Extension.
pub trait ResponseExt: private::Sealed + Sized {
Expand Down Expand Up @@ -94,7 +94,10 @@ pub trait ResponseExt: private::Sealed + Sized {

/// Downloads transfers the file from path as an attachment.
#[cfg(feature = "fs")]
fn download<T>(path: T, name: Option<&str>) -> impl Future<Output = Result<Self>> + Send
fn download<T>(
path: T,
name: Option<&str>,
) -> impl std::future::Future<Output = Result<Self>> + Send
where
T: AsRef<std::path::Path> + Send;

Expand Down Expand Up @@ -231,7 +234,9 @@ impl ResponseExt for Response {

let mut resp = Self::attachment(&format!("attachment; filename=\"{value}\""));
*resp.body_mut() = Body::from_stream(tokio_util::io::ReaderStream::new(
tokio::fs::File::open(path).await.map_err(Error::from)?,
tokio::fs::File::open(path)
.await
.map_err(crate::Error::from)?,
));
Ok(resp)
}
Expand Down
1 change: 1 addition & 0 deletions viz-smol/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod unix;
pub mod tls;

/// Serve a future using [`smol`]'s TCP listener.
#[allow(clippy::missing_errors_doc)]
pub async fn serve<'ex, E, L>(executor: E, listener: L, router: Router) -> io::Result<()>
where
E: Borrow<Executor<'ex>> + Clone + Send + 'ex,
Expand Down
2 changes: 1 addition & 1 deletion viz-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ keywords = ["async", "framework", "http", "service", "web"]
categories = ["asynchronous", "network-programming", "web-programming"]

[dependencies]
viz.workspace = true
viz = { workspace = true, features = ["fs"] }

bytes.workspace = true
futures-util.workspace = true
Expand Down

0 comments on commit 39066c8

Please sign in to comment.