How to implement the ToString trait to create a comma-delimited string without a trailing comma?
<p>I have this code:</p>

<pre><code>struct A {
    names: Vec&lt;String&gt;,
}

impl ToString for A {
    fn to_string(&amp;self) -&gt; String {
        // code here
    }
}

fn main() {
    let a = A {
        names: vec!["Victor".to_string(), "Paul".to_string()],
    };
    println!("A struct contains: [{}].", a.to_string());
}
</code></pre>

<p>Expected output:</p>

<blockquote>
  <p>A struct contains: [Victor, Paul].</p>
</blockquote>

<p>What is the best way to implement this trait to achieve the goal? I have tried some weird 'for each' and other variants, but each one gives me a trailing comma like this:</p>

<blockquote>
  <p>Victor, Paul,</p>
</blockquote>

<p>Of course I can pop it off later, but I am interested in the language so I want to know the best practice of this. This is just an example of what I've tried, but it does not matter, I am asking how to do this most efficiently.</p>