mhost 0.11.3

Fast, async DNS lookup library and CLI -- modern dig/host replacement with parallel multi-server queries, DoH, DoT, subdomain discovery, and zone verification
Documentation
// Copyright 2017-2021 Lukas Pustina <lukas@pustina.de>
//
// Derived from trust-dns by Benjamin Fry <benjaminfry@me.com>
// cf. https://github.com/bluejekyll/trust-dns
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use serde::{Deserialize, Serialize};

#[derive(Default, Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
#[allow(clippy::upper_case_acronyms)]
pub struct NULL {
    anything: Option<Vec<u8>>,
}

impl NULL {
    /// Construct a new NULL RData
    pub fn new() -> NULL {
        Default::default()
    }

    /// Constructs a new NULL RData with the associated data
    pub fn with(anything: Vec<u8>) -> NULL {
        NULL {
            anything: Some(anything),
        }
    }

    /// Returns the buffer stored in the NULL
    pub fn anything(&self) -> Option<&[u8]> {
        self.anything.as_ref().map(|bytes| &bytes[..])
    }
}

#[doc(hidden)]
impl From<hickory_resolver::proto::rr::rdata::NULL> for NULL {
    fn from(null: hickory_resolver::proto::rr::rdata::NULL) -> Self {
        NULL {
            anything: {
                let bytes = null.anything();
                if bytes.is_empty() {
                    None
                } else {
                    Some(bytes.to_vec())
                }
            },
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn null_new_is_empty() {
        let null = NULL::new();
        assert_eq!(null.anything(), None);
    }

    #[test]
    fn null_with_data() {
        let null = NULL::with(vec![1, 2, 3]);
        assert_eq!(null.anything(), Some([1u8, 2, 3].as_slice()));
    }
}