What's up everyone!
I've been study Rust for the last couple of months and always trying to get closer of my actual stack which is around Laravel environment.
For me, as a PHP Developer, jump into Rust is a truly hard task since I never went to Functional Programming before, however I found a way to make this "easier".
Rust AFAIK
The whole ecosystem is made up of different packages and you should add it as you need it, unlike Laravel which has a really robust environment around the framework.
So my first impression was that I had to learn how to use the base packages:
- Dotenvy
- Chrono
- Time
- Uuid
- and so on.
But when it comes to Web Development (API mostly) you have to choose an framework among many which is already there. Like:
- Actix (currently using)
- Axum (evaluating)
- Rocket (people always tell me to not use it, still don't know why)
and none of them has the opinionated "structure" of Laravel, so I decided to create mine.
Laravel inside Rust
Why am I talking about Laravel? Because the "MVC" structure it gives us is elegant enough for small projects with Rust Web.
Things started to make sense when I coded Rust using the opinionated Laravel framework. Here's a structure of what I'm talking about:
./src
├── app.rs
├── config.rs
├── http
│ ├── controllers
│ │ ├── leaderboard_controller.rs
│ │ ├── mod.rs
│ │ └── submissions_controller.rs
│ ├── mod.rs
│ └── requests
│ ├── leaderboard_request.rs
│ ├── mod.rs
│ └── submission_request.rs
├── main.rs
├── models
│ ├── leaderboard.rs
│ ├── mod.rs
│ └── submission.rs
└── repositories
├── leaderboard_repository.rs
├── mod.rs
└── submission_repository.rs
This project is currently using:
and you can check my mess in this Pull Request
The question is: would be a good thing to follow this thoughts while working with Rust? The simplicity and good structure for maintaining is what I'm always looking in a project.
Also I'm thinking to write some series on how is my process migrating from PHP to Rust, would interest you read something like that?
Hope to see your thoughts here and thanks!
Top comments (9)
nice write-up! I miss a “one-person” framework in Rust too, I think such a project could make Rust more intuitive in the web scenario.
have you seen loco.rs? it’s around this idea, heavily focused in the Rails way (which I think Laravel share some similarities)
What you have done is amazing, I always thought that laravel way to structure their modules is pretty organized and well structured, so, why not do this in another language if is well structured, right!?
Great job, looking forward to see the next steps of the project!
really interesting! thanks for sharing!
I'm starting to learn somethings about Laravel and it's curious to know that we can "copy" some structures... since I'm starting I don't know if Rust has its own structure but I think that if that's helping and working, there's no problem at all
AFAIK, Rust developers doesn't like to opinionated in other developers Structures.
However, there's plenty of Rust projects that you will look at the README and see something like "this is an opinionated structure using the framework X and Y tooling".
I'm not a fan of copying things without know how it works behind the curtains, and that's why I'm following the Laravel structure.
Amazing post as always @danielhe4rt. Thanks for sharing your knowledge with us.
Great article, Dan!
What challenges did you face as a PHP developer transitioning to Rust, and how does incorporating Laravel into Rust development help address these challenges?
First actual challenge was migrating to a heavy typed language. Rust doesn't allow you to do lazy typing like PHP.
Also the immutability is a thing here. In PHP you can do whatever you want with the variables, in Rust, it must follow some patterns if you want to mutate it.
The Laravel come when I need a more specific way to bring Web/Console/Database opinionated development, since I know each part of the framework not only in the "end user" side, but some internals as well.
Excellent article @danielhe4rt ! Discovering new possibilities in technology is the action that opens up opportunities and universes for us as developers. Comparing what we are studying with what we already know is a good way to deeply understand the difference between the tools 😁
nothing like a good old laravel architecture in every possible programming language
Some comments may only be visible to logged-in visitors. Sign in to view all comments.