File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,8 +16,16 @@ struct InfoFile<'a> {
1616
1717#[ proc_macro]
1818pub fn include_files ( _: TokenStream ) -> TokenStream {
19- let info_file = include_str ! ( "../info.toml" ) ;
20- let exercises = toml:: de:: from_str :: < InfoFile > ( info_file)
19+ // Remove `\r` on Windows
20+ let info_file = String :: from_utf8 (
21+ include_bytes ! ( "../info.toml" )
22+ . iter ( )
23+ . copied ( )
24+ . filter ( |c| * c != b'\r' )
25+ . collect ( ) ,
26+ )
27+ . expect ( "Failed to parse `info.toml` as UTF8" ) ;
28+ let exercises = toml:: de:: from_str :: < InfoFile > ( & info_file)
2129 . expect ( "Failed to parse `info.toml`" )
2230 . exercises ;
2331
Original file line number Diff line number Diff line change @@ -94,10 +94,17 @@ impl InfoFile {
9494 /// Community exercises: Parse the `info.toml` file in the current directory.
9595 pub fn parse ( ) -> Result < Self > {
9696 // Read a local `info.toml` if it exists.
97- let slf = match fs:: read_to_string ( "info.toml" ) {
98- // Leaking is fine since the info file is used until the end of the program.
99- Ok ( file_content) => toml:: de:: from_str :: < Self > ( file_content. leak ( ) )
100- . context ( "Failed to parse the `info.toml` file" ) ?,
97+ let slf = match fs:: read ( "info.toml" ) {
98+ Ok ( file_content) => {
99+ // Remove `\r` on Windows.
100+ // Leaking is fine since the info file is used until the end of the program.
101+ let file_content =
102+ String :: from_utf8 ( file_content. into_iter ( ) . filter ( |c| * c != b'\r' ) . collect ( ) )
103+ . context ( "Failed to parse `info.toml` as UTF8" ) ?
104+ . leak ( ) ;
105+ toml:: de:: from_str :: < Self > ( file_content)
106+ . context ( "Failed to parse the `info.toml` file" ) ?
107+ }
101108 Err ( e) => {
102109 if e. kind ( ) == ErrorKind :: NotFound {
103110 return toml:: de:: from_str ( EMBEDDED_FILES . info_file )
You can’t perform that action at this time.
0 commit comments