Repository: actix/actix-web
File: src/fs.rs (Rust)

Code before:
    modified: Option<SystemTime>,
    cpu_pool: Option<CpuPool>,
    encoding: Option<ContentEncoding>,
    only_get: bool,
    status_code: StatusCode,
}

impl NamedFile {
    /// Attempts to open a file in read-only mode.
    ///
    /// # Examples
    ///
    /// ```rust
    /// use actix_web::fs::NamedFile;
    ///
    /// let file = NamedFile::open("foo.txt");
    /// ```
    pub fn open<P: AsRef<Path>>(path: P) -> io::Result<NamedFile> {
        use header::{ContentDisposition, DispositionType, DispositionParam};
        let path = path.as_ref().to_path_buf();

        // Get the name of the file and use it to construct default Content-Type
        // and Content-Disposition values
        let content_type;
        let content_disposition;
        {
            let filename = match path.file_name() {
                Some(name) => name.to_string_lossy(),
                None => return Err(io::Error::new(
                    io::ErrorKind::InvalidInput,
                    "Provided path has no filename")),
            };

            content_type = guess_mime_type(&path);
            let disposition_type = match content_type.type_() {
                mime::IMAGE | mime::TEXT | mime::VIDEO => DispositionType::Inline,
                _ => DispositionType::Attachment,
            };
            content_disposition = ContentDisposition {
                disposition: disposition_type,
                parameters: vec![
                    DispositionParam::Filename(
                        header::Charset::Ext("UTF-8".to_owned()),
                        None,
                        filename.as_bytes().to_vec(),
                    )
                ],
            };
        }

        let file = File::open(&path)?;

Review comment (suggestion):
I would suggest to return directly instead of assigning:
```rust
let (content_type, content_disposition) = {
...
}```

Code after:
    modified: Option<SystemTime>,
    cpu_pool: Option<CpuPool>,
    encoding: Option<ContentEncoding>,
    only_get: bool,
    status_code: StatusCode,
}

impl NamedFile {
    /// Attempts to open a file in read-only mode.
    ///
    /// # Examples
    ///
    /// ```rust
    /// use actix_web::fs::NamedFile;
    ///
    /// let file = NamedFile::open("foo.txt");
    /// ```
    pub fn open<P: AsRef<Path>>(path: P) -> io::Result<NamedFile> {
        use header::{ContentDisposition, DispositionType, DispositionParam};
        let path = path.as_ref().to_path_buf();

        // Get the name of the file and use it to construct default Content-Type
        // and Content-Disposition values
        let (content_type, content_disposition) =
        {
            let filename = match path.file_name() {
                Some(name) => name.to_string_lossy(),
                None => return Err(io::Error::new(
                    io::ErrorKind::InvalidInput,
                    "Provided path has no filename")),
            };

            let ct = guess_mime_type(&path);
            let disposition_type = match ct.type_() {
                mime::IMAGE | mime::TEXT | mime::VIDEO => DispositionType::Inline,
                _ => DispositionType::Attachment,
            };
            let cd = ContentDisposition {
                disposition: disposition_type,
                parameters: vec![
                    DispositionParam::Filename(
                        header::Charset::Ext("UTF-8".to_owned()),
                        None,
                        filename.as_bytes().to_vec(),
                    )
                ],
            };
            (ct, cd)
        };

        let file = File::open(&path)?;