elrnv / vtkio

Visualization ToolKit (VTK) file parser and writer
Apache License 2.0
55 stars 12 forks source link

unresolved imports `vtkio::export_ascii`, `vtkio::import` #32

Closed hunter1992 closed 1 year ago

hunter1992 commented 1 year ago

When I tested the import/export example, the following error occurred:

error[E0432]: unresolved imports `vtkio::export_ascii`, `vtkio::import`
 --> src/main.rs:2:13
  |
2 | use vtkio::{export_ascii, import};
  |             ^^^^^^^^^^^^  ^^^^^^ no `import` in the root
  |             |
  |             no `export_ascii` in the root

I want to ask how to solve this problem?

elrnv commented 1 year ago

Thank you for flagging this! The example in the readme is slightly outdated. I just pushed a commit fixing it. The correct usage is found on docs.rs. In general, for Rust libraries, docs.rs is a better source for finding examples because they are often at least compiled with the corresponding revision of the code.

With the current API, the example should be:

use vtkio::model::*; // import model definition of a VTK file
fn main() {
    use std::path::PathBuf;
    let file_path = PathBuf::from("assets/tet.vtk");

    let mut vtk_file = Vtk::import(&file_path)
        .expect(&format!("Failed to load file: {:?}", file_path));

    vtk_file.version = Version::new((4,2)); // arbitrary change

    vtk_file.export_ascii(&file_path)
        .expect(&format!("Failed to save file: {:?}", file_path));
}