title: Implement graph-like data structure in Rust
body: <p>I have a data structure which can be represented as a unidirectional graph between some structs linked with link objects because links contain metadata.</p>
  
  <p>It looks something like this:</p>
  
  <pre><code>struct StateMachine {
      resources: Vec&lt;Resource&gt;,
      links: Vec&lt;Link&gt;,
  }
  struct Resource {
      kind: ResourceType,
        // ...
  }
  
  enum LinkTarget {
      ResourceList(Vec&lt;&amp;Resource&gt;),
      LabelSelector(HashMap&lt;String, String&gt;),
  }
  
  struct Link {
      from: LinkTarget,
      to: LinkTarget,
      metadata: SomeMetadataStruct,
  }
  </code></pre>
  
  <p>The whole structure needs to be mutable because I need to be able to add and remove links and resources at runtime. Because of this, I cannot use the normal lifetime model and bind the resources to the parent struct's lifetime.</p>
  
  <p>I understand that I need <a href="https://doc.rust-lang.org/book/first-edition/choosing-your-guarantees.html" rel="noreferrer">to "choose my own guarantee"</a> by picking the appropriate type, but I'm not sure what's the best way to solve this problem.</p>