Tumgik
#when the blog will be purged is undetermined
dragonpro809 · 1 month
Note
would you be willing to make an archive blog for your older stories? i loved them a lot so i’d still love to be able to read them :( if not, thats okay!!
Heya! After receiving this ask, I'd be more than willing too! I honestly had no idea I still had some followers who read some of my older works, and I simply assumed I was a dead blog atp after having gone dark across most of my social media platforms. But, I can and will make an archive blog of sorts that will contain all my older stories and some of my newer ones as well! I'll also make a masterpost in that blog as well to help people find a specific story easily (I will figure out how to do that ^^). Thank you so much for this ask, whoever you are. Just knowing people would still like to read my writing, as old and as cringy as it is, really warms my heart <3
1 note · View note
tsworman · 7 years
Text
tyD-Torrent
My first Rust software is complete. For years I’ve been wanting to cleanup a large torrent directory I had. It got bigger with each release as the maintainers of the torrent changed file names and folder structures. Loading the new torrent into my client downloaded the new files but it left the old ones around. I wasn’t quite sure how to resolve this and I believe some existing software did it but was poorly documented. 
This year when I went to update I decided it was time to do something about it. I had been wanting to learn at least a little bit of Rust so that I could keep up with the news stories on Hacker News. Even after coding this I don’t see what all the fuss is about but the build system is fancy and the libraries available are fairly nice.
This application reads a torrent file and finds all filenames and paths of files that are part of it. It then scans a provided directory and lists all the files you should delete to make your structure match that of the torrent (purge extra files). If you pass the -d or --delete option it will actually remove those files. In my case this cleared up 36GB on one torrent directory alone. YMMV as it depends how sloppy you were with maintaining your folders.
Code here:
https://github.com/tsworman/tyD-torrent
build with:
cargo build
Run with:
tyD_torrent somefile.torrent /home/username/somefilev181/
and an optional -d or --delete flag.
What do I think about Rust? Cargo is super nice and the packages available are great. The built in collections left me a bit perplexed as they seemed like super odd choices. References vs pointers was a bit confusing coming from C/C++ but I appreciate their simplicity. 
I have an issue with understanding Lifetimes. I get why a variable needs a longer lifetime and I understand the reference to it will be freed. I don’t get the syntax or understand Cow (copy on write).. I mean I know I need them when a colleciton or type doesn’t implement copy and it throws me a lifetime error. I can’t figure out the syntax. It doesn’t seem intuitive and despite reading multiple blogs and posts about it, I think all that I’ve found are written from the perspective of someone using it for a while (duh...) and they don’t really address the questions a n00b Rust person would have. I spent about 3 hours reading, writing examples, and trying to think up where I’d use each use case. It’s still a bit fuzzy and I think I’d approach in this manner at the moment:
1) Lifetime Error, crap this will be annoying.
2) Try making it a reference &, and dereference when needed. This is great as long as the type or function you are calling implements clone or doesn’t care if it’s a pointer or reference.
3) Try using clone or to_string and then just convert it back later for simplicity sake
4) Try one of the crazy syntax examples I have and specify a lifetime.
5) Read more about Box and Enums since it seems if you get really lost you just wrap things and problems will go away.
That sounds like a horrible plan, but I need to read more and maybe come up with better use cases for this stuff. The examples I found were bare bones and didn’t have as much detail as I would have liked. The worst is when the syntax in the examples or blogs is outdated because Rust has evolved already during it’s short lifetime.
Can I return a LinkedList of str? No, str u8 is an undetermined size as compile time. LinkedList<&str>? Sure. LinkedList<Path>, no. LinkedList<&Path>, no. LinkedList<&PathBuf>, sure. 
I’m not sure I’d grab for Rust again over C/C++, though I understand I’ve written safer code for having done so this time. At the moment it’s not more readable or expressive than C/C++ for me. It’s also not nearly as well documented as C/C++ libraries are because of the time they have been around. This will all probably change over time. 15 years of C coding with pointers, function pointers, and reference handling really has made a lasting mark on me.
TL;DR; Learning Rust by writing your first piece of software may not be the best idea. It’s hard to change how I think about memory management from C/C++. I wrote a torrent directory cleaner and you can download and try it out here: https://github.com/tsworman/tyD-torrent
0 notes