minor updates

This commit is contained in:
Benjamin Fry 2015-08-07 20:10:39 -07:00
parent 488961b8ad
commit 9507c67aad
4 changed files with 43 additions and 10 deletions

4
Cargo.lock generated Normal file
View File

@ -0,0 +1,4 @@
[root]
name = "trust-dns"
version = "0.1.0"

View File

@ -1,5 +1,5 @@
pub mod rr;
#[test]
fn it_works() {

View File

@ -0,0 +1 @@
mod record_types;

View File

@ -1,8 +1,5 @@
use core::convert::{From, Into}
/**
*/
#[derive(Debug)]
pub enum RecordType {
A, // 1 RFC 1035[1] IPv4 Address record
@ -50,28 +47,59 @@ pub enum RecordType {
// TODO make these a macro...
pub impl Into<String> for RecordType {
fn into(self) -> String {
/// Convert from RecordType to String
///
/// ```
/// assert_eq!("A", A.into());
/// ```
pub impl From<RecordType> for String {
fn from(self) -> Self {
match self {
A => "A",
AAAA => "AAAA",
CNAME => "CNAME",
NS => "NS",
SOA => "SOA",
_ => unimplemented!,
_ => unimplemented!(),
}
}
}
pub impl Into<i32> for RecordType {
fn into(self) -> String {
pub impl From<String> for RecordType {
fn from(self) -> Self {
match self.as_slice() {
"A" => A,
"AAAA" => AAAA,
"CNAME" => CNAME,
"NS" => NS,
"SOA" => SOA,
_ => unimplemented!(),
}
}
}
pub impl From<RecordType> for i32 {
fn from(self) -> Self {
match self {
A => 1,
AAAA => 28,
CNAME => 5,
NS => 2,
SOA => 6,
_ => unimplemented!,
_ => unimplemented!(),
}
}
}
pub impl From<i32> for RecordType {
fn from(self) -> Self {
1 => A,
28 => AAAA,
5 => CNAME,
2 => NS,
6 => SOA,
_ => unimplemented!(),
}
}