u/Accurate_Gift_3929

▲ 0 r/learnrust+1 crossposts

Rust discourages OOP style code?

I'm building a tree builder struct (with a `build()` method) that has multiple fields that I want to be able to mutate. It seems Rust does not like it when I attempt to mutate multiple fields of that struct.

It seems functional/composition style is much favored over using struct fields. Is this the way I should be thinking about design patterns in Rust? Should I avoid OOP wherever possible?

I prefer OOP because it does result in cleaner code where I don't have to pass in every variable to functions.

reddit.com
u/Accurate_Gift_3929 — 9 days ago
▲ 9 r/rust

Questions on iterators, copying, consuming.

I'm creating a parser that requires me to create an iterator several times to check the next char. I'm wondering if this is causing a copy every time. And is it possible to use the same iterator to get the next char (perhaps in other cases previous chars, etc) within the same loop?

Question 2: Why do iterators consume preceding elements? I imagine an iterator being a separate entity that can traverse back and forth on a collection. This doesn't seem to be the case in with Rust.

reddit.com
u/Accurate_Gift_3929 — 22 days ago
▲ 0 r/rust

Sturdy Framework - Yet another Rust web framework

Hello there. I've been building a web framework for Rust. I'm coming from the PHP/Laravel world where fast dynamic typing can help you prototype and build very quickly. However, I've come to love Rust and would love to start building with it. It is slower to prototype, but with a blazing fast compiled runtime, memory safety and modern features for a systems programming language, I couldn't resist.

So why not Axum? Or Rocket? Or the ten other major Rust web frameworks? Well, being honest, none of them really clicked with me. They seem to be some combination of too light and/or too macro-heavy, and macros aren't the reason I like Rust.

This framework (Sturdy Framework) aims to reduce the use of macros, which will end up with more verbose code, but much easier to understand at a glance. I do not like the hidden nature of macros, and I will choose verbosity over obscurity (in most cases).

Features (currently):

  • Variable supporting routing system
  • Struct based action endpoints
  • File watchers for auto compilation, and auto reloading

Upcoming:

  • Finish database integration (had no need for it yet for the documentation website, so it is not yet finished)
  • Better feature parity with frameworks like PHP's Laravel (or Ruby's Rails)

Feedback/code review is very much sought after. The project is in a pre-alpha state, so please let me know if you have issues with installation. Appreciate your time!

Link (docs): https://sturdyframework.com
Docs source (as an example): https://github.com/jayclees/framework-docs
Starter template: https://github.com/jayclees/sturdy-project
Framework source: https://github.com/jayclees/framework

As a note I will say, the routing system is custom built, and was the hardest part of building this framework as I had to build a tokenizer to handle multi-variable route segments. There is even a struct called a SegmentReconciliator which parses incoming paths and "reconciliates" or matches route segments.

reddit.com
u/Accurate_Gift_3929 — 24 days ago