0
I’m trying to use the package pdf_extract to manipulate pdfs in Rust. I would like to extract the string from the pdf. I saw that the function for this is set so:
pub fn extract_text<P: AsRef<Path>>(path: P) -> Result<String, OutputError>
So I used the extract to manage the error:
use pdf_extract::extract_text;
fn main() {
let text = extract_text("meu.pdf").expect("Unable to read file");
println!("{}", &text)
}
This, however, returns an error:
thread 'main' panicked at 'attempted to leave type `linked_hash_map::Node<std::vec::Vec<u8>, object::Object>` uninitialized, which is invalid', /rustc/2fd73fabe469357a12c2c974c140f67e7cdd76d0/library/core/src/mem/mod.rs:671:9
As the error message is different from the one I used in expect, I don’t know what the mistake means. It seems to me, the command let text = extract_text("meu.pdf").expect("Unable to read file"); worked, but still gave error. What I’m doing wrong here?
I don’t know the library in question, but as far as I can tell... the
expectonly acts in the instance ofResultwhich he was called. It’s not like he’s atry/catchthat captures any "error" (does not exist in Rust). It seems to me that thepanic!happened before the functionextract_textcould even have returned theResult. Thepanic!came from(...)/library/core/src/mem/mod.rs:671:9.– Luiz Felipe