Skip to content

Commit ac13bb5

Browse files
committed
Add support for MACADDR type using eui48 crate. Create feature eui48.
1 parent 32efe30 commit ac13bb5

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ unix_socket = { version = "0.5", optional = true }
4040
uuid = { version = "0.1", optional = true }
4141
security-framework = { version = "0.1.2", optional = true }
4242
bit-vec = { version = "0.4", optional = true }
43+
eui48 = { version = "0.1", optional = true }
4344

4445
[dev-dependencies]
4546
url = "0.5"

src/types/eui48.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
extern crate eui48;
2+
3+
use std::io::prelude::*;
4+
5+
use self::eui48::MacAddress;
6+
7+
use types::{FromSql, ToSql, Type, IsNull, SessionInfo};
8+
use Result;
9+
use util;
10+
11+
impl FromSql for MacAddress {
12+
fn from_sql<R: Read>(_: &Type, raw: &mut R, _: &SessionInfo) -> Result<MacAddress> {
13+
let mut bytes = [0; 6];
14+
try!(util::read_all(raw, &mut bytes));
15+
Ok(MacAddress::new(bytes))
16+
}
17+
18+
accepts!(Type::Macaddr);
19+
}
20+
21+
impl ToSql for MacAddress {
22+
fn to_sql<W: Write + ?Sized>(&self, _: &Type, w: &mut W, _: &SessionInfo) -> Result<IsNull> {
23+
try!(w.write_all(self.as_bytes()));
24+
Ok(IsNull::No)
25+
}
26+
27+
accepts!(Type::Macaddr);
28+
to_sql_checked!();
29+
}

src/types/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ mod rustc_serialize;
6767
mod serde_json;
6868
#[cfg(feature = "chrono")]
6969
mod chrono;
70+
#[cfg(feature = "eui48")]
71+
mod eui48;
7072

7173
/// A structure providing information for conversion methods.
7274
pub struct SessionInfo<'a> {
@@ -658,6 +660,7 @@ impl WrongTypeNew for WrongType {
658660
/// | chrono::DateTime&lt;FixedOffset&gt; | TIMESTAMP WITH TIME ZONE |
659661
/// | chrono::NaiveDate | DATE |
660662
/// | chrono::NaiveTime | TIME |
663+
/// | eui48::MacAddress | MACADDR |
661664
/// | uuid::Uuid | UUID |
662665
/// | bit_vec::BitVec | BIT, VARBIT |
663666
///

0 commit comments

Comments
 (0)