Skip to content

Add File::open_with() function to open files with options (e.g. read/write) #55762

Closed
@Timmmm

Description

@Timmmm

The current way to open a file is this:

File::open("foo.txt")

But if you want to open a file in with any options you do this:

use std::fs::OpenOptions;

let mut file = OpenOptions::new()
    .read(true)
    .write(true)
    .open("foo.txt");

It's weird that the options object does the actual opening. I propose that we deprecate OpenOptions::open() and add File::open_with(path: &str, options: &OpenOptions).

let mut file = File::open_with("foo.txt", OpenOptions::new().read().write());

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions