Skip to content

add a macro rule open_file! #12912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
electricface opened this issue Mar 15, 2014 · 1 comment
Closed

add a macro rule open_file! #12912

electricface opened this issue Mar 15, 2014 · 1 comment

Comments

@electricface
Copy link

macro_rules! open_file(
    ($path_str:expr) => (
        ::std::io::File::open(&Path::new( $path_str ))
    );
    ($path_str:expr, rw ) => ( 
        ::std::io::File::open_mode(&Path::new( $path_str ) , ::std::io::Open,
        ::std::io::ReadWrite )
    ); 
    ($path_str:expr, w ) => ( 
        ::std::io::File::open_mode(&Path::new( $path_str ) , ::std::io::Open,
        ::std::io::Write )
    );
    ($path_str:expr, a ) => ( 
        ::std::io::File::open_mode(&Path::new( $path_str ) , ::std::io::Append,
        ::std::io::Write )
    );  
)

example

fn main(){
    let file_path="message.txt";
    let mut file = try_or!(
        open_file!(file_path ,w ),
        "can't open file `{}` : [{}]", file_path,e
        );
}

about macro rule try_or! see #12911

@alexcrichton
Copy link
Member

Closing for reasons found here: #12915 (comment)

flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 13, 2024
Don't lint indexing_slicing lints on proc macros

This pr fixes rust-lang/rust-clippy#12824

Even though the issue mentions the indexing case only, it was easy to apply the fix to the slicing case as well.

changelog: [`out_of_bounds_indexing`, `indexing_slicing`]: Don't lint on procedural macros.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants