Rust question 

I have Route defined like this:

#[derive(Copy, Clone)]
pub struct Route {
path: &'static str,
action: fn(&&str, &mut Response),
}

I've implemented new(), get_path(), set_path(), get_action(), and set_action(), all of them public.

I have a vec! of Routes, and I want to iterate over it and find the first Route that has a `path` that matches a provided &str. I'm using

vec!.into_iter().find(|x| x.get_path() == my_str)

but I'm getting borrowing/mutability errors. Any ideas?

Rust question 

Check out src/main.rs and src/lib.rs if you want to see the full Baby's First Web Server. git.noelle.codes/noelle/rust-w

Show thread
Follow

Rust question 

(As should be apparent from my comment in the last toot, I'm entirely open to the idea that I'm Doing This Wrong, but please do focus on the area in question. I'm trying to solve a problem, not open up the floor for general commentary.)

Rust question 

@noelle I got a 404 when I tried to go to the link.

Rust question 

@waterbear whoops, it was set private. I've solved the issue, though, thanks!

Rust question 

@noelle I think I know the issue. You need the definition of get_path to take &self not &mut self. I'll upload a playpen link shortly

Rust question 

@waterbear Yep. Like I said, I solved the issue.

Sign in to participate in the conversation
Elekk: Gameing and Other Delightful Pursuits

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!