Skip to content
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

convert \r\n -> \n in include_str! macro #63681

Closed
wants to merge 1 commit into from

Commits on Aug 18, 2019

  1. convert \r\n -> \n in include_str! macro

    Ideally, the meaning of the program should be independent of the line
    endings used, because, for example, git can change line endings during
    a checkout.
    
    We currently do line-ending conversion in almost all cases, with
    `include_str` being an exception. This commit removes this exception,
    bringing `include_str` closer in behavior to string literals.
    
    Note that this is technically a breaking change.
    
    In case that you really mean to include a string with DOS line
    endings, you can use `include_bytes!` macro which is guaranteed to not
    do any translation, like this
    
        pub fn my_text() -> &'static str {
            unsafe {
                std::str::from_utf8_unchecked(MY_TEXT_BYTES);
            }
        }
    
        const MY_TEXT_BYTES: &[u8] = include_bytes("my_text.bin");
    
        #[test]
        fn test_encoding() {
            std::str::from_utf8(MY_TEXT_BYTES)
    	    .unwrap();
        }
    matklad committed Aug 18, 2019
    Configuration menu
    Copy the full SHA
    df73b26 View commit details
    Browse the repository at this point in the history