DEV Community


Posted on • Updated on • Originally published at

A Web App in Rust - 17 Conclusion

Welcome back! For the last time!

I'm going to split up my thoughts into 2 sections, the first will be my thoughts on the post series. The second part will focus on rust.

A Web App in Rust Thoughts

I'll take some time now to talk about the drawbacks and issues in our application still. I'm going to work backwards from the last chapter to the first and hopefully you'll have some ideas of how to fix it and can tell me!

Major note about the entire project is I kept most of the code in one file. In reality we should have split the code into handler files and had our main point to the handlers but to me having everything in one file made it so I could keep everything in my head.

The error handler was the one section that felt like it could go in its own file but I kept it in just for consistency. I debated doing the models in main but that didn't feel right.

16 - Our application cannot handle being shutdown, there is nothing making sure it stays up which is terrible. I'm not entirely sure what the answer is. Maybe a systemd or sysinit script, I've used both before but I don't think I got them right. It certainly didn't feel as stable as nginx and systemctl enable.

15 - Logging is currently kind of lackluster. I would love to get java style stack traces. The other thing missing is log rotation, currently the log gets either put on the screen or a file but it grows forever. Does rust have log rotation? Should it be happening on the linux level instead?

14 - Error handling was quite fun, it was probably the newest thing I learned through rust. My only question about error handling was if there was a way to print out what panic would have printed but to a log. This way instead of the cleaned up error we get the full disaster.

13 - Connection pooling was fine.

12 - Passwords. Ah Passwords, I wonder if maybe this should have been done earlier in the login pages. My focus was on getting the structure of the application done rather than being correct but it is a very simple addition.

11 - User Profiles were fine.

10 - Commenting was fine for the most part, I do wish that I had made the database a little simpler and skipped the foreign key being the user id. It would have been enough to just save the username as I could do the lookup with that as well. We also skipped making replies as I thought it was getting unruly but replies could be an interesting problem.

09 - The index page, my biggest issue here was design, I was going to use bootstrap to quickly build a half decent page but then I thought it felt too big and complex. Keeping it bare bones personally allowed me to see the whole project.

08 - Submitting new posts, this along with comments was fun to set up and play around with. I don't remember having any issues but I'm sure there were.

07 - Logging in a user, I am curious if the actix_identity does indeed use a hashmap, I looked at the source code and it looks really straightforward, I just don't understand it. I'm also wondering if relying on actix_identity is enough to manage sessions.

06 - Registering a user was fine, I wish I added karma as part of the project, that could have been a fun placeholder even if I did nothing with it like the comment replies.

05 - The database was a big topic to cover and I wonder if it is a valid schema and if I screwed up the foreign keys and relationships somehow. I don't have much experience with SQL or databases so it was really just winging it.

04 - The forms were straightforward, however a big piece missing is the CSRF token, no idea what its for but it sounded important everywhere else and I didn't even bother with it.

03 - Complex templates and temples could probably be merged together as they aren't big enough to warrant separate posts but they still make logical sense to be broken up in my head.

02 - The templates were fine, simple but a better design must be possible without classes and just using plain html. I'll need to think about it. I should add static files to actix so that some styling could be done and I think adding static files would be relatively simple but I'm leaving it out for now.

01 - The beginning was okay!

  • The ones I say are fine, might be fine because I screwed them up so badly I don't even know!

Thoughts on Rust

I've tried to pick up rust and work through the rust book a couple of times now and I can never get too deep. I don't think it fits my style of learning, I like throwing my self into doing things. So this post series was me putting together something I have a grasp on in a language I don't understand. That's why the focus of this series was the forest and the structure. I wanted to see how rust organized things how the language would affect things.

Ultimately I don't think the language matter too much. I've written applications in node and python and rust felt very much like them. The gain here may be the types but I don't think I was doing enough logic to really see rust shine. I didn't fight too much with borrow checker, I didn't really get help from the compiler except a few times. I used clone a few times to get past compiler errors, String and str are still a mystery and so on.

I also may have picked the wrong project, a web app I'm starting to see is just gluing things together. The actual business logic is harder to implement and create.

So I don't know how to feel about rust. I like the language but next time I'll do something that is less glue work and see what the hype is about.

Overall this was quite a bit of fun and I hope you enjoyed it. Hopefully it was easy to follow along and to see how a web application is structured. I don't think you would learn much about rust itself here but that's okay!

Thank you all!

Sources of Inspiration

Really enjoyed this tutorial, even knowing flask it was fun and really easy to follow.

This was a good tutorial, really fast and I think you'd need to really sit and think to follow it. I just copied the code.

All of the crates had great documentation that I relied on the most and for the most part everything just worked.

Top comments (2)

thorhenrik profile image
ThorHenrik • Edited

Hi, i dont know if you will see this, but i just need to say i fell in love with this project, i was completely new to rust, looking for tutorials on how to make website with rust, and i couldnt find anything good before i found this tutorial. i need to say Thank you!.
I dont know if you have time or intrest in it, but i would love if you would help with producing more content about web application in rust.
Have you heard about SurrealDB, that looks amazing, would love if you would make a website where you use this, i think you are going to like it. and having header and footer that will show on all sites are really something i like to learn more about. a login/signup system is something i also think is advantageous to have more content about on the internet, so would love if it were more tutorials that show that in rust.
i would also love to get a better understanding about a search function in the website, to search for content avilable across the whole website.
I think SurrealDB is perfect for this? (i didnt have any previous knowlegde about database before ths tutorial, apart from knowing what a database is and how tables look).
im writing this comment because of multiple reasons, one is that i really fell in love with this tutorial, since it explained and showed me so much about how a website can be set up in rust. and also i struggeled really hard to find a tutorial including everything you included (until i found this), and also this tutorial is from 2020, so some stuff is maybe outdated?, would love to se if there is a more updated way of doing this.
this is unrelevant, but i myself, is planning on making a website where i am going to write articles (tutorials actually, since i feel many tutorials out there is not explaining smaller problems users can have, then many users will then be stuck on small problems and after hours and hours, give up, so that is why i would like to make a website with alittle more error friendly tutorials). this is a dream for me.
i really love your content and i understand if this, what i asked for, if this is not of intrest for you to make. But i think this could/would be a fun project, and maybe a visit down memory lane, since you have already had a simular project before. This will increase the content online about website development in rust (and i feel it is not easy to find, and then find updated versions).
Thank you in advance, either if you like this request, or if this is not something you want to spend time on <3

krowemoh profile image

Thank you, this is a lovely comment! I'll think about doing refresh of this set of articles but I haven't developed as a rust programmer too much so I'm not sure if there will be much value.

Surrealdb definitely looks interesting and I'll be giving that a shot at some point.