How do I iterate over elements of a struct?
<p>I'm writing a small client/server program for encrypted network communications and have the following struct to allow the endpoints to negotiate capabilities.</p>

<pre><code>struct KeyExchangePacket {
    kexinit: u8,
    replay_cookie: [u8; 32],
    kex_algorithms: String,
    kgen_algorithms: String,
    encryption_algorithms: String,
    mac_algorithms: String,
    compression_algorithms: String,
    supported_languages: String,
}
</code></pre>

<p>I need to convert the fields into bytes in order to send them over a <code>TcpStream</code>, but I currently have to convert them one at a time.</p>

<pre><code>send_buffer.extend_from_slice(kex_algorithms.as_bytes());
send_buffer.extend_from_slice(kgen_algorithms.as_bytes());
etc...
</code></pre>

<p>Is there a way to iterate over the fields and push their byte values into a buffer for sending?</p>