Repository: actix/actix-web
File: src/application.rs (Rust)

Code before:
    {
        {
            let parts = self.parts.as_mut().expect("Use after finish");

            // get resource handler
            let mut found = false;
            for &mut (ref pattern, ref handler) in &mut parts.resources {
                if handler.is_some() && pattern.pattern() == path {
                    found = true;
                    break;
                }
            }

            if !found {
                let mut handler = ResourceHandler::default();
                handler.method(method).with(f);
                let pattern = Resource::new(handler.get_name(), path);
                parts.resources.push((pattern, Some(handler)));
            } else {
                for &mut (ref pattern, ref mut handler) in &mut parts.resources {
                    if let Some(ref mut handler) = *handler {
                        if pattern.pattern() == path {
                            handler.method(method).with(f);
                            break;
                        }
                    }
                }
            }
        }
        self
    }

    /// Configure scope for common root path.
    ///
    /// Scopes collect multiple paths under a common path prefix.
    /// Scope path can contain variable path segments as resources.
    ///
    /// ```rust
    /// # extern crate actix_web;
    /// use actix_web::{http, App, HttpRequest, HttpResponse};
    ///
    /// fn main() {
    ///     let app = App::new().scope("/{project_id}", |scope| {
    ///         scope
    ///             .resource("/path1", |r| r.f(|_| HttpResponse::Ok()))
    ///             .resource("/path2", |r| r.f(|_| HttpResponse::Ok()))
    ///             .resource("/path3", |r| r.f(|_| HttpResponse::MethodNotAllowed()))
    ///     });
    /// }
    /// ```
    ///

Review comment (suggestion):
`Some(out)` is possible only on `iterator.next() == None` (or on the end of iterator). So you may improve the loop at line 340 like this:

```
for (pattern, handler) in iterator {
    ...
    if if pattern.pattern() == path {
        ...
        return self; // <<<<<<<<<<<<< note return self instead of break None
    }
}

// if the path was not found among patterns:
let mut handler = ResourceHandler::default();
handler.method(method).with(f);
let pattern = Resource::new(handler.get_name(), path);
parts.resources.push((pattern, Some(handler)));

return self;
```

And there is no need to create variable `let out = { huuuuge block };`

Code after:
    {
        {
            let parts: &mut ApplicationParts<S> = self.parts.as_mut().expect("Use after finish");

            let out = {
                // get resource handler
                let mut iterator = parts.resources.iter_mut();

                loop {
                    if let Some(&mut (ref pattern, ref mut handler)) = iterator.next() {
                        if let Some(ref mut handler) = *handler {
                            if pattern.pattern() == path {
                                handler.method(method).with(f);
                                break None;
                            }
                        }
                    } else {
                        let mut handler = ResourceHandler::default();
                        handler.method(method).with(f);
                        let pattern = Resource::new(handler.get_name(), path);
                        break Some((pattern, Some(handler)));
                    }
                }
            };

            if let Some(out) = out {
                parts.resources.push(out);
            }
        }

        self
    }

    /// Configure scope for common root path.
    ///
    /// Scopes collect multiple paths under a common path prefix.
    /// Scope path can contain variable path segments as resources.
    ///
    /// ```rust
    /// # extern crate actix_web;
    /// use actix_web::{http, App, HttpRequest, HttpResponse};
    ///
    /// fn main() {
    ///     let app = App::new().scope("/{project_id}", |scope| {
    ///         scope
    ///             .resource("/path1", |r| r.f(|_| HttpResponse::Ok()))
    ///             .resource("/path2", |r| r.f(|_| HttpResponse::Ok()))
    ///             .resource("/path3", |r| r.f(|_| HttpResponse::MethodNotAllowed()))
    ///     });
    /// }
    /// ```