Merge pull request #783 from timando/master

Add support for eui48 version 1.0
This commit is contained in:
Steven Fackler 2021-06-02 21:07:36 -04:00 committed by GitHub
commit ff7d88f901
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 58 additions and 2 deletions

View File

@ -15,6 +15,7 @@ derive = ["postgres-derive"]
with-bit-vec-0_6 = ["bit-vec-06"]
with-chrono-0_4 = ["chrono-04"]
with-eui48-0_4 = ["eui48-04"]
with-eui48-1 = ["eui48-1"]
with-geo-types-0_6 = ["geo-types-06"]
with-geo-types-0_7 = ["geo-types-0_7"]
with-serde_json-1 = ["serde-1", "serde_json-1"]
@ -30,6 +31,7 @@ postgres-derive = { version = "0.4.0", optional = true, path = "../postgres-deri
bit-vec-06 = { version = "0.6", package = "bit-vec", optional = true }
chrono-04 = { version = "0.4.16", package = "chrono", default-features = false, features = ["clock"], optional = true }
eui48-04 = { version = "0.4", package = "eui48", optional = true }
eui48-1 = { version = "1.0", package = "eui48", optional = true }
geo-types-06 = { version = "0.6", package = "geo-types", optional = true }
geo-types-0_7 = { version = "0.7", package = "geo-types", optional = true }
serde-1 = { version = "1.0", package = "serde", optional = true }

View File

@ -0,0 +1,27 @@
use bytes::BytesMut;
use eui48_1::MacAddress;
use postgres_protocol::types;
use std::error::Error;
use crate::{FromSql, IsNull, ToSql, Type};
impl<'a> FromSql<'a> for MacAddress {
fn from_sql(_: &Type, raw: &[u8]) -> Result<MacAddress, Box<dyn Error + Sync + Send>> {
let bytes = types::macaddr_from_sql(raw)?;
Ok(MacAddress::new(bytes))
}
accepts!(MACADDR);
}
impl ToSql for MacAddress {
fn to_sql(&self, _: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
let mut bytes = [0; 6];
bytes.copy_from_slice(self.as_bytes());
types::macaddr_to_sql(bytes, w);
Ok(IsNull::No)
}
accepts!(MACADDR);
to_sql_checked!();
}

View File

@ -194,6 +194,8 @@ mod bit_vec_06;
mod chrono_04;
#[cfg(feature = "with-eui48-0_4")]
mod eui48_04;
#[cfg(feature = "with-eui48-1")]
mod eui48_1;
#[cfg(feature = "with-geo-types-0_6")]
mod geo_types_06;
#[cfg(feature = "with-geo-types-0_7")]

View File

@ -24,6 +24,7 @@ circle-ci = { repository = "sfackler/rust-postgres" }
with-bit-vec-0_6 = ["tokio-postgres/with-bit-vec-0_6"]
with-chrono-0_4 = ["tokio-postgres/with-chrono-0_4"]
with-eui48-0_4 = ["tokio-postgres/with-eui48-0_4"]
with-eui48-1 = ["tokio-postgres/with-eui48-1"]
with-geo-types-0_6 = ["tokio-postgres/with-geo-types-0_6"]
with-geo-types-0_7 = ["tokio-postgres/with-geo-types-0_7"]
with-serde_json-1 = ["tokio-postgres/with-serde_json-1"]

View File

@ -55,7 +55,8 @@
//! | ------- | ----------- | ------------------ | ------- |
//! | `with-bit-vec-0_6` | Enable support for the `bit-vec` crate. | [bit-vec](https://crates.io/crates/bit-vec) 0.6 | no |
//! | `with-chrono-0_4` | Enable support for the `chrono` crate. | [chrono](https://crates.io/crates/chrono) 0.4 | no |
//! | `with-eui48-0_4` | Enable support for the `eui48` crate. | [eui48](https://crates.io/crates/eui48) 0.4 | no |
//! | `with-eui48-0_4` | Enable support for the 0.4 version of the `eui48` crate. | [eui48](https://crates.io/crates/eui48) 0.4 | no |
//! | `with-eui48-1` | Enable support for the 1.0 version of the `eui48` crate. | [eui48](https://crates.io/crates/eui48) 1.0 | no |
//! | `with-geo-types-0_6` | Enable support for the 0.6 version of the `geo-types` crate. | [geo-types](https://crates.io/crates/geo-types/0.6.0) 0.6 | no |
//! | `with-geo-types-0_7` | Enable support for the 0.7 version of the `geo-types` crate. | [geo-types](https://crates.io/crates/geo-types/0.7.0) 0.7 | no |
//! | `with-serde_json-1` | Enable support for the `serde_json` crate. | [serde_json](https://crates.io/crates/serde_json) 1.0 | no |

View File

@ -30,6 +30,7 @@ runtime = ["tokio/net", "tokio/time"]
with-bit-vec-0_6 = ["postgres-types/with-bit-vec-0_6"]
with-chrono-0_4 = ["postgres-types/with-chrono-0_4"]
with-eui48-0_4 = ["postgres-types/with-eui48-0_4"]
with-eui48-1 = ["postgres-types/with-eui48-1"]
with-geo-types-0_6 = ["postgres-types/with-geo-types-0_6"]
with-geo-types-0_7 = ["postgres-types/with-geo-types-0_7"]
with-serde_json-1 = ["postgres-types/with-serde_json-1"]
@ -61,6 +62,7 @@ criterion = "0.3"
bit-vec-06 = { version = "0.6", package = "bit-vec" }
chrono-04 = { version = "0.4", package = "chrono", default-features = false }
eui48-04 = { version = "0.4", package = "eui48" }
eui48-1 = { version = "1.0", package = "eui48" }
geo-types-06 = { version = "0.6", package = "geo-types" }
geo-types-07 = { version = "0.7", package = "geo-types" }
serde-1 = { version = "1.0", package = "serde" }

View File

@ -106,7 +106,8 @@
//! | `runtime` | Enable convenience API for the connection process based on the `tokio` crate. | [tokio](https://crates.io/crates/tokio) 1.0 with the features `net` and `time` | yes |
//! | `with-bit-vec-0_6` | Enable support for the `bit-vec` crate. | [bit-vec](https://crates.io/crates/bit-vec) 0.6 | no |
//! | `with-chrono-0_4` | Enable support for the `chrono` crate. | [chrono](https://crates.io/crates/chrono) 0.4 | no |
//! | `with-eui48-0_4` | Enable support for the `eui48` crate. | [eui48](https://crates.io/crates/eui48) 0.4 | no |
//! | `with-eui48-0_4` | Enable support for the 0.4 version of the `eui48` crate. | [eui48](https://crates.io/crates/eui48) 0.4 | no |
//! | `with-eui48-1` | Enable support for the 1.0 version of the `eui48` crate. | [eui48](https://crates.io/crates/eui48) 1.0 | no |
//! | `with-geo-types-0_6` | Enable support for the 0.6 version of the `geo-types` crate. | [geo-types](https://crates.io/crates/geo-types/0.6.0) 0.6 | no |
//! | `with-geo-types-0_7` | Enable support for the 0.7 version of the `geo-types` crate. | [geo-types](https://crates.io/crates/geo-types/0.7.0) 0.7 | no |
//! | `with-serde_json-1` | Enable support for the `serde_json` crate. | [serde_json](https://crates.io/crates/serde_json) 1.0 | no |

View File

@ -0,0 +1,18 @@
use eui48_1::MacAddress;
use crate::types::test_type;
#[tokio::test]
async fn test_eui48_params() {
test_type(
"MACADDR",
&[
(
Some(MacAddress::parse_str("12-34-56-AB-CD-EF").unwrap()),
"'12-34-56-ab-cd-ef'",
),
(None, "NULL"),
],
)
.await
}

View File

@ -19,6 +19,8 @@ mod bit_vec_06;
mod chrono_04;
#[cfg(feature = "with-eui48-0_4")]
mod eui48_04;
#[cfg(feature = "with-eui48-1")]
mod eui48_1;
#[cfg(feature = "with-geo-types-0_6")]
mod geo_types_06;
#[cfg(feature = "with-geo-types-0_7")]