diff --git a/Cargo.toml b/Cargo.toml index 7de2404..4505d10 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,6 @@ version = "0.17.0" default = ["url"] [dependencies] -arrayref = "0.3" byteorder = "1.3.1" data-encoding = "2.1" multibase = "0.9.1" diff --git a/src/protocol.rs b/src/protocol.rs index 006962d..f4516ab 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -1,6 +1,5 @@ use crate::onion_addr::Onion3Addr; use crate::{Error, Result}; -use arrayref::array_ref; use byteorder::{BigEndian, ByteOrder, ReadBytesExt, WriteBytesExt}; use data_encoding::BASE32; use multihash::Multihash; @@ -106,6 +105,11 @@ pub enum Protocol<'a> { Wss(Cow<'a, str>), } +#[inline] +fn array_ref(s: &[T]) -> &[T; N] { + unsafe { &*(&s[..N] as *const [T] as *const [T; N]) } +} + impl<'a> Protocol<'a> { /// Parse a protocol value from the given iterator of string slices. /// @@ -298,7 +302,7 @@ impl<'a> Protocol<'a> { let (data, rest) = split_at(12, input)?; let port = BigEndian::read_u16(&data[10..]); Ok(( - Protocol::Onion(Cow::Borrowed(array_ref!(data, 0, 10)), port), + Protocol::Onion(Cow::Borrowed(array_ref::<10, _>(&data)), port), rest, )) } @@ -306,7 +310,7 @@ impl<'a> Protocol<'a> { let (data, rest) = split_at(37, input)?; let port = BigEndian::read_u16(&data[35..]); Ok(( - Protocol::Onion3((array_ref!(data, 0, 35), port).into()), + Protocol::Onion3((array_ref::<35, _>(&data), port).into()), rest, )) }