@@ -3,7 +3,7 @@ use std::io::Read;
33use std:: io:: { BufReader , BufWriter , Write } ;
44use std:: path:: Path ;
55
6- use anyhow:: anyhow;
6+ use anyhow:: { anyhow, Context } ;
77use na:: Vector3 ;
88use vtkio:: model:: { DataSet , Version , Vtk } ;
99use vtkio:: { export_be, import_be} ;
@@ -38,7 +38,7 @@ pub fn particles_from_coords<RealOut: Real, RealIn: Real>(
3838 coords : & Vec < RealIn > ,
3939) -> Result < Vec < Vector3 < RealOut > > , anyhow:: Error > {
4040 if coords. len ( ) % 3 != 0 {
41- anyhow ! ( "The number of values in the particle data point buffer is not divisable by 3" ) ;
41+ anyhow ! ( "The number of values in the particle data point buffer is not divisible by 3" ) ;
4242 }
4343
4444 let num_points = coords. len ( ) / 3 ;
@@ -79,9 +79,7 @@ pub fn particles_from_dataset<R: Real>(
7979pub fn particles_from_xyz < R : Real , P : AsRef < Path > > (
8080 xyz_file : P ,
8181) -> Result < Vec < Vector3 < R > > , anyhow:: Error > {
82- let xyz_file = xyz_file. as_ref ( ) ;
83-
84- let file = File :: open ( xyz_file) ?;
82+ let file = File :: open ( xyz_file) . context ( "Unable to open xyz file for reading" ) ?;
8583 let mut reader = BufReader :: new ( file) ;
8684
8785 let mut buffer = [ 0u8 ; 3 * 4 ] ;
@@ -114,7 +112,7 @@ pub fn particles_from_xyz<R: Real, P: AsRef<Path>>(
114112#[ allow( dead_code) ]
115113pub fn to_binary_f32 < R : Real , P : AsRef < Path > > ( file : P , values : & [ R ] ) -> Result < ( ) , anyhow:: Error > {
116114 let file = file. as_ref ( ) ;
117- let file = File :: create ( file) ?;
115+ let file = File :: create ( file) . context ( "Unable to create binary file" ) ?;
118116 let mut writer = BufWriter :: new ( file) ;
119117
120118 for v in values {
0 commit comments