title: Cannot borrow in a Rc as mutable
body: <p>First of all I'm new with Rust :-)</p>
  
  <p>The problem:
  I want to create a module called RestServer that contain the methods ( actix-web ) to add routes and start the server.</p>
  
  <pre><code>struct Route
  {
     url: String,
     request: String,
     handler: Box&lt;dyn Fn(HttpRequest) -&gt; HttpResponse&gt;
  }
  
  
  impl PartialEq for Route {
     fn eq(&amp;self, other: &amp;Self) -&gt; bool {
       self.url == other.url
     }
  }
  
  impl Eq for Route {}
  
  impl Hash for Route {
     fn hash&lt;H: Hasher&gt;(&amp;self, hasher: &amp;mut H) {
        self.url.hash(hasher);
     }
  }
  </code></pre>
  
  <p>this is the route structure, this structure containe the the route url, the request type ( GET, POST etc ) and hanlder is the function that have to catch the request and return a HTTPResponse</p>
  
  <pre><code>pub struct RestServer
  {
     scopes: HashMap&lt;String, Rc&lt;HashSet&lt;Route&gt;&gt;&gt;,
     routes: HashSet&lt;Route&gt;,
     host: String,
  }
  
  impl RestServer {
  
     pub fn add_route(self, req: &amp;str, funct: impl Fn(HttpRequest) -&gt; HttpResponse + 'static,
                   route: &amp;str, scope: Option&lt;&amp;str&gt;) -&gt; RestServer
     {
         let mut routes_end = self.routes;
         let mut scopes_end = self.scopes;
         let url = self.host;
         let route = Route {
            url: String::from(route),
            request: String::from(req),
            handler: Box::new(funct)
      };
  
      if let Some(x) = scope {
          if let Some(y) = scopes_end.get(x) {
              let mut cloned_y = Rc::clone(y);
              cloned_y.insert(route);
              scopes_end.insert(String::from(x), cloned_y);
          }else {
              let mut hash_scopes = HashSet::new();
              hash_scopes.insert(route);
              scopes_end.insert(String::from(x), Rc::new(hash_scopes));
          }
      } else {
          routes_end.insert(route);
      }
  
      RestServer {
          scopes: scopes_end,
          routes: routes_end,
          host: String::from(url)
      }
    }
  </code></pre>
  
  <p>the latest code is the implementation of RestServer. 
  The most important part is the <strong>add_route</strong> function, this function receive as paramente the route that is a string, the function handler, the request string and the scope.
  First i create the route object.
  I check if the scope exist into the HashMap, if yes i have to take the actual scope and update the HashSet.</p>
  
  <p>When i build the code i get the following error</p>
  
  <pre><code>   error[E0596]: cannot borrow data in an `Rc` as mutable
     --&gt; interface/src/rest/mod.rs:60:17
     |
  60 |                 cloned_y.insert(route);
     |                 ^^^^^^^^ cannot borrow as mutable
     |
     = help: trait `DerefMut` is required to modify through a dereference, but it is not 
       implemented for `std::rc::Rc&lt;std::collections::HashSet&lt;rest::Route&gt;&gt;`
  </code></pre>
  
  <p>I know that the compiler give me some help but honestly i have no idea how to do that or if i can do with some easy solution.
  After a large search in google i found a solution in RefCell, but is not so much clear</p>
  
  <p>Thanks in advance for your help</p>