fn write_qname(buf: &mut Vec<u8>, domain: &str) -> io::Result<()> {
        // Decode this label into the original unicode.
        // TODO Switch to using our own idna::Config. (but we can't use disallowed_by_std3_ascii_rules).
        let domain = match idna::domain_to_ascii(domain) {
            Err(e) => {
                bail!(InvalidData, "invalid dns name '{0}': {1}", domain, e);
            }
            Ok(domain) => domain,
        };

        if !domain.is_empty() && domain != "." {
            for label in domain.split_terminator('.') {
                if label.is_empty() {
                    bail!(InvalidData, "empty label in domain name '{}'", domain);
                }

                if label.len() > 63 {
                    bail!(InvalidData, "label '{0}' longer than 63 characters", label);
                }

                // Write the length.
                buf.push(label.len() as u8);

                // Then the actual label.
                buf.extend_from_slice(label.as_bytes());
            }
        }

        buf.push(0);

        Ok(())
    }
/// Writes a Unicode domain name into the supplied [`Vec<u8>`].
///
/// Used for writing out a encoded ASCII domain name into a DNS message. Will
/// returns the Unicode domain name, as well as the length of this qname (ignoring
/// any compressed pointers) in bytes.
///
// TODO Support compression.
Writes a Unicode domain name into the supplied [`Vec`].
Used for writing out a encoded ASCII domain name into a DNS message. Will
returns the Unicode domain name, as well as the length of this qname (ignoring
any compressed pointers) in bytes.


Writes a Unicode domain name into the supplied [ ` Vec ` ] . Used for writing out a encoded ASCII domain name into a DNS message . Will returns the Unicode domain name as well as the length of this qname ( ignoring any compressed pointers ) in bytes .
fn write_qname(buf: &mut Vec<u8>, domain: &str) -> io::Result<()> {
        // Decode this label into the original unicode.
        // TODO Switch to using our own idna::Config. (but we can't use disallowed_by_std3_ascii_rules).
        let domain = match idna::domain_to_ascii(domain) {
            Err(e) => {
                bail!(InvalidData, "invalid dns name '{0}': {1}", domain, e);
            }
            Ok(domain) => domain,
        };
        if !domain.is_empty() && domain != "." {
            for label in domain.split_terminator('.') {
                if label.is_empty() {
                    bail!(InvalidData, "empty label in domain name '{}'", domain);
                }
                if label.len() > 63 {
                    bail!(InvalidData, "label '{0}' longer than 63 characters", label);
                }
                // Write the length.
                buf.push(label.len() as u8);
                // Then the actual label.
                buf.extend_from_slice(label.as_bytes());
            }
        }
        buf.push(0);
        Ok(())
    }
fn write_qname ( buf : & mut Vec < u8 > , domain : & str ) -> io :: Result < ( ) > { // Decode this label into the original unicode. // TODO Switch to using our own idna::Config. (but we can't use disallowed_by_std3_ascii_rules). let domain = match idna :: domain_to_ascii ( domain ) { Err ( e ) => { bail ! ( InvalidData " " domain e ) ; } Ok ( domain ) => domain , } ; if ! domain . is_empty ( ) && domain != " " { for label in domain . split_terminator ( '.' ) { if label . is_empty ( ) { bail ! ( InvalidData " " domain ) ; } if label . len ( ) > 63 { bail ! ( InvalidData " " label ) ; } // Write the length. buf . push ( label . len ( ) as u8 ) ; // Then the actual label. buf . extend_from_slice ( label . as_bytes ( ) ) ; } } buf . push ( 0 ) ; Ok ( ( ) ) }
Writes a Unicode domain name into the supplied [`Vec<u8>`].
Writes a Unicode domain name into the supplied [ ` Vec<u8 > ` ] .
buf
&mut Vec<u8>
domain
&str