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 {
pub fn new() -> NULL {
Default::default()
}
pub fn with(anything: Vec<u8>) -> NULL {
NULL {
anything: Some(anything),
}
}
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()));
}
}