
Against my better judgement, I started learning Rust and set out to build my own PDF file parser from scratch.
Just the first hour in, I learned a lot more about Rust ownership and how PDF files are actually formatted and stored, it didn't take as much code as I thought TBH.
At first the whole
&
Symbol was throwing me off, I come from the javascript world but after some studying it started to make sense. You're letting the compiler know that you're passing a reference to data memory. Your code can copy values by making a direct copy of the value in memory and storying that cloned data to a new spot in memory, or you can simply pass in the refrence to the address in memory of that data, preventing you from having to waste memory when you really don't need it.
That led me down the rabbit hole on how rust handles memory...Basically as i understand it, the Rust compiler looks everytime you create a variable at when the last reference to that variable is, and allows you to pass write permissions to another variable so long as no other variable is reading or trying to write to it.
So to start playing around with rust and playing around with all of this, I made a basic reader.rs file which reads from the pdf and returns the bytes.
reader.rs is called from the main.rs file, and then I have it logging some of the test from the pdf. I just took my own resume as a test file and saw the pdf objects rendered as test which was really cool to see how pdf files are stored, next up is to parse the pdf objects so I can parse out the text of the resume without all the xml like object sytax text in there...
Rust is fun.
#rust #javascript #pdf #webdev #softwareengineer



English





