Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate csv;
- use std::error::Error;
- use std::process;
- fn run() -> Result<(), Box<Error>> {
- let file_path = std::path::Path::new("test.csv");
- let mut wtr = csv::Writer::from_path(file_path).unwrap();
- wtr.write_record(&["City", "State", "Population", "Latitude", "Longitude"])?;
- wtr.write_record(&["Davidsons Landing", "AK", "", "65.2419444", "-165.2716667"])?;
- wtr.write_record(&["Kenai", "AK", "7610", "60.5544444", "-151.2583333"])?;
- wtr.write_record(&["Oakman", "AL", "", "33.7133333", "-87.3886111"])?;
- wtr.flush()?;
- Ok(())
- }
- fn main() {
- if let Err(err) = run() {
- println!("{}", err);
- process::exit(1);
- }
- }
- let mut file = OpenOptions::new()
- .write(true)
- .append(true)
- .open("test.csv")
- .unwrap();
- let mut wtr = csv::Writer::from_writer(file);
- let mut file = OpenOptions::new()
- .write(true)
- .create(true)
- .append(true)
- .open("test.csv")
- .unwrap();
- let mut wtr = csv::Writer::from_writer(file);
Add Comment
Please, Sign In to add comment