mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-02 00:39:20 +00:00
Rustfmt
This commit is contained in:
parent
ce156a349c
commit
c7fd0e4a87
@ -3,7 +3,6 @@ use std::path::Path;
|
|||||||
|
|
||||||
const TEST_FILE_NAME: &str = "SampleTextFile.txt";
|
const TEST_FILE_NAME: &str = "SampleTextFile.txt";
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
create_required_files();
|
create_required_files();
|
||||||
|
|
||||||
let read_str_result = fs::read_to_string(TEST_FILE_NAME);
|
let read_str_result = fs::read_to_string(TEST_FILE_NAME);
|
||||||
@ -20,7 +19,6 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn create_required_files() {
|
fn create_required_files() {
|
||||||
let file_path = Path::new(TEST_FILE_NAME);
|
let file_path = Path::new(TEST_FILE_NAME);
|
||||||
|
|
||||||
@ -28,5 +26,4 @@ fn create_required_files(){
|
|||||||
fs::write(&file_path, "This is the file content.").unwrap();
|
fs::write(&file_path, "This is the file content.").unwrap();
|
||||||
println!("File created.");
|
println!("File created.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -3,7 +3,6 @@ use std::path::Path;
|
|||||||
|
|
||||||
const TEST_FILE_NAME: &str = "SampleTextFile.txt";
|
const TEST_FILE_NAME: &str = "SampleTextFile.txt";
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
create_required_files();
|
create_required_files();
|
||||||
|
|
||||||
let read_str_result = fs::read_to_string(TEST_FILE_NAME);
|
let read_str_result = fs::read_to_string(TEST_FILE_NAME);
|
||||||
@ -14,12 +13,10 @@ fn main() {
|
|||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
panic!("Error reading file.");
|
panic!("Error reading file.");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn create_required_files() {
|
fn create_required_files() {
|
||||||
let file_path = Path::new(TEST_FILE_NAME);
|
let file_path = Path::new(TEST_FILE_NAME);
|
||||||
|
|
||||||
@ -27,5 +24,4 @@ fn create_required_files(){
|
|||||||
fs::write(file_path, "This is the file content.").unwrap();
|
fs::write(file_path, "This is the file content.").unwrap();
|
||||||
println!("File created.");
|
println!("File created.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -29,7 +29,8 @@ fn main() {
|
|||||||
|
|
||||||
for line in buffered_input_file.lines() {
|
for line in buffered_input_file.lines() {
|
||||||
if let Ok(line) = line {
|
if let Ok(line) = line {
|
||||||
let write_result =buffered_file_writer.write(format!("Line {} : {}\n", line_number, line).as_bytes());
|
let write_result =
|
||||||
|
buffered_file_writer.write(format!("Line {} : {}\n", line_number, line).as_bytes());
|
||||||
if write_result.is_err() {
|
if write_result.is_err() {
|
||||||
eprintln!("Write result error: {}", write_result.unwrap_err());
|
eprintln!("Write result error: {}", write_result.unwrap_err());
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{PathBuf};
|
use std::path::PathBuf;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
create_required_files();
|
create_required_files();
|
||||||
let mut path_buffer = PathBuf::new();
|
let mut path_buffer = PathBuf::new();
|
||||||
|
|
||||||
@ -20,12 +19,7 @@ fn main() {
|
|||||||
assert!(!meta_data.permissions().readonly());
|
assert!(!meta_data.permissions().readonly());
|
||||||
} else {
|
} else {
|
||||||
panic!("Could not get metadata");
|
panic!("Could not get metadata");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_required_files() {
|
fn create_required_files() {
|
||||||
@ -39,12 +33,10 @@ fn create_required_files(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !file_path.exists() {
|
if !file_path.exists() {
|
||||||
|
|
||||||
let text = "This is the first line of the text.
|
let text = "This is the first line of the text.
|
||||||
This is the second line.
|
This is the second line.
|
||||||
And this is the third and the last line.";
|
And this is the third and the last line.";
|
||||||
fs::write(file_path, text).unwrap();
|
fs::write(file_path, text).unwrap();
|
||||||
println!("File created.");
|
println!("File created.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user