src/ ├── lib.rs <-- The Root (Registers all other files) ├── config.rs <-- Constants (Repo, User, Branch) ├── types.rs <-- Structs (MenuItem, RenderedPage) ├── parser.rs <-- Markdown parsing logic ├── utils.rs <-- DOM helpers (Observer, Highlighting) └── app.rs <-- The Main Yew Component
-
for web-sys, setter-style methods mutate self and return &mut Self.
-
This is a closure, sort of a hook in the case where
|| → a closure that takes no arguments
() → returns the unit type“A function that takes and return but it return nothing and does nothing.”
- The expected signature (conceptually).
FnOnce() -> impl FnOnce()Meaning:
The effect runs once (or when deps change) It returns a cleanup function The cleanup function runs when:
- the component unmounts, or
- the dependencies change
When NO cleanup to perform, there are something must be return.
That “something” is:
|| ()example in the case of hook cases
use_effect(move || {
let observer = create_observer();
// with cleanup
|| {
observer.disconnect();
}
});use_effect(move || {
setup_observer();
// no cleanup
|| ()
});Rust will shout error if it doent return. but omit something will cause error as well as it will not return expected types.
use_effect(move || {
//try to omit value from closure
setup_observer();
});So somehow something must be return which is nothing
It satisfies the type system by saying:
“Here i shall return it back to you, but its nothing, and doesnt do anothing. But atleast you know"