Try to write a variable of type ethereum_types::H256
to a .csv file. When I did it, it was not writing anything to the file.
I tried to change it into String
, with to_string()
, then something was written to the file, but not what I expected. I tried using write_record()
but it does also not write anyting to the file.
use std::error::Error;
use csv::Writer;
use std::fs::OpenOptions;
use ethereum_types::H256;
fn example(data: H256) -> Result<(), Box<dyn Error>> {
let file = OpenOptions::new()
.write(true)
.create(true)
.append(true)
.open("/home/shashi/test.csv")
.unwrap();
let mut wtr = Writer::from_writer(file);
wtr.write_field(data)?;
wtr.write_record(None::<&[u8]>)?;
Ok(())
}
fn main()
{
let s= H256::zero();
for n in 1..5
{
if let Err(err) = example(s)
{
println!("{}", err);
}
}
}
This question already has an answer here:
Try to write a variable of type ethereum_types::H256
to a .csv file. When I did it, it was not writing anything to the file.
I tried to change it into String
, with to_string()
, then something was written to the file, but not what I expected. I tried using write_record()
but it does also not write anyting to the file.
use std::error::Error;
use csv::Writer;
use std::fs::OpenOptions;
use ethereum_types::H256;
fn example(data: H256) -> Result<(), Box<dyn Error>> {
let file = OpenOptions::new()
.write(true)
.create(true)
.append(true)
.open("/home/shashi/test.csv")
.unwrap();
let mut wtr = Writer::from_writer(file);
wtr.write_field(data)?;
wtr.write_record(None::<&[u8]>)?;
Ok(())
}
fn main()
{
let s= H256::zero();
for n in 1..5
{
if let Err(err) = example(s)
{
println!("{}", err);
}
}
}
I epected
"0x0000000000000000000000000000000000000000000000000000000000000000"
but it was
"0x0000...0000"