From c6ac5b896367f24396a0024f0b0a7451b715b7fc Mon Sep 17 00:00:00 2001 From: Daan de Graaf Date: Mon, 21 Jan 2019 18:22:32 +0100 Subject: [PATCH] Get rid of tempfile dependency. --- Cargo.toml | 1 - src/fs.rs | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b54d866fe..f927e24e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -129,7 +129,6 @@ tokio-uds = { version="0.2", optional = true } [dev-dependencies] env_logger = "0.6" serde_derive = "1.0" -tempfile = "3.0" [build-dependencies] version_check = "0.1" diff --git a/src/fs.rs b/src/fs.rs index 91a43e117..814f2d96a 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -128,17 +128,30 @@ impl NamedFile { /// # Examples /// /// ```rust - /// extern crate tempfile; /// extern crate actix_web; /// /// use actix_web::fs::NamedFile; - /// use tempfile::tempfile; /// use std::io::{self, Write}; + /// use std::env; + /// # use std::fs::{self, File}; + /// # use std::path::PathBuf; + /// # + /// # fn path() -> PathBuf { + /// # let mut path = env::temp_dir(); + /// # path.push("actix-web-named-file-test-from-file"); + /// # path + /// # } + /// # + /// # fn tempfile() -> Result { + /// # let file = File::create(path())?; + /// # Ok(file) + /// # } /// /// fn main() -> io::Result<()> { /// let mut file = tempfile()?; /// file.write_all(b"Hello, world!")?; /// let named_file = NamedFile::from_file(file, "foo.txt")?; + /// # fs::remove_file(path())?; /// Ok(()) /// } /// ``` @@ -169,17 +182,30 @@ impl NamedFile { /// # Examples /// /// ```rust - /// extern crate tempfile; /// extern crate actix_web; /// - /// use actix_web::fs::{NamedFile, DefaultConfig}; - /// use tempfile::tempfile; + /// use actix_web::fs::{DefaultConfig, NamedFile}; /// use std::io::{self, Write}; + /// use std::env; + /// # use std::fs::{self, File}; + /// # use std::path::PathBuf; + /// # + /// # fn path() -> PathBuf { + /// # let mut path = env::temp_dir(); + /// # path.push("actix-web-named-file-test-from-file-with-config"); + /// # path + /// # } + /// # + /// # fn tempfile() -> Result { + /// # let file = File::create(path())?; + /// # Ok(file) + /// # } /// /// fn main() -> io::Result<()> { /// let mut file = tempfile()?; /// file.write_all(b"Hello, world!")?; /// let named_file = NamedFile::from_file_with_config(file, "foo.txt", DefaultConfig)?; + /// # fs::remove_file(path())?; /// Ok(()) /// } /// ``` @@ -225,6 +251,7 @@ impl NamedFile { _cd_map: PhantomData, }) } + /// Attempts to open a file in read-only mode using provided configuration. /// /// # Examples