Skip to content

Commit

Permalink
Merge #256
Browse files Browse the repository at this point in the history
256: Refactor adapters r=Dylan-DPC a=kinggoesgaming

Currently in a hurry, will expand the description tomorrow or so.
Also these changes particularly around the `to_<adaptertype>` method names need discussion before merge

**I'm submitting a ...**
  - [ ] bug fix
  - [x] feature enhancement
  - [ ] deprecation or removal
  - [x] refactor

# Description
Refactors the adapters

# Motivation
One of the last steps in the great refactor

# Tests
Current tests pass.... More tests need to be added

# Related Issue(s)
#124


Co-authored-by: Hunar Roop Kahlon <hunar.roop@gmail.com>
  • Loading branch information
bors[bot] and kinggoesgaming committed Jun 26, 2018
2 parents 590d56c + 6c2a94a commit aa1cc48
Show file tree
Hide file tree
Showing 10 changed files with 689 additions and 241 deletions.
32 changes: 0 additions & 32 deletions src/adapter.rs

This file was deleted.

39 changes: 39 additions & 0 deletions src/adapter/core_support/macros.rs
@@ -0,0 +1,39 @@
// Copyright 2013-2014 The Rust Project Developers.
// Copyright 2018 The Uuid Project Developers.
//
// See the COPYRIGHT file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

macro_rules! hyphenated_write {
($f:ident, $format:expr, $bytes:expr) => {{
let data1 = u32::from($bytes[0]) << 24
| u32::from($bytes[1]) << 16
| u32::from($bytes[2]) << 8
| u32::from($bytes[3]);

let data2 = u16::from($bytes[4]) << 8 | u16::from($bytes[5]);

let data3 = u16::from($bytes[6]) << 8 | u16::from($bytes[7]);

write!(
$f,
$format,
data1,
data2,
data3,
$bytes[8],
$bytes[9],
$bytes[10],
$bytes[11],
$bytes[12],
$bytes[13],
$bytes[14],
$bytes[15]
)
}};
}
256 changes: 256 additions & 0 deletions src/adapter/core_support/mod.rs
@@ -0,0 +1,256 @@
// Copyright 2013-2014 The Rust Project Developers.
// Copyright 2018 The Uuid Project Developers.
//
// See the COPYRIGHT file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use core::fmt;
use prelude::*;

#[macro_use]
mod macros;

impl fmt::Display for super::UuidHyphenated {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::LowerHex::fmt(self, f)
}
}

impl<'a> fmt::Display for super::UuidHyphenatedRef<'a> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::LowerHex::fmt(self, f)
}
}

impl fmt::Display for super::UuidSimple {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::LowerHex::fmt(self, f)
}
}

impl<'a> fmt::Display for super::UuidSimpleRef<'a> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::LowerHex::fmt(self, f)
}
}

impl fmt::Display for super::UuidUrn {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::LowerHex::fmt(self, f)
}
}

impl<'a> fmt::Display for super::UuidUrnRef<'a> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::LowerHex::fmt(self, f)
}
}

impl fmt::LowerHex for super::UuidHyphenated {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
hyphenated_write!(
f,
"{:08x}-\
{:04x}-\
{:04x}-\
{:02x}{:02x}-\
{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
self.0.as_bytes()
)
}
}

impl<'a> fmt::LowerHex for super::UuidHyphenatedRef<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
hyphenated_write!(
f,
"{:08x}-\
{:04x}-\
{:04x}-\
{:02x}{:02x}-\
{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
self.0.as_bytes()
)
}
}

impl fmt::LowerHex for super::UuidSimple {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for byte in self.0.as_bytes() {
write!(f, "{:02x}", byte)?
}

Ok(())
}
}

impl<'a> fmt::LowerHex for super::UuidSimpleRef<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for byte in self.0.as_bytes() {
write!(f, "{:02x}", byte)?
}

Ok(())
}
}

impl fmt::LowerHex for super::UuidUrn {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
hyphenated_write!(
f,
"urn:uuid:\
{:08x}-\
{:04x}-\
{:04x}-\
{:02x}{:02x}-\
{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
self.0.as_bytes()
)
}
}

impl<'a> fmt::LowerHex for super::UuidUrnRef<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
hyphenated_write!(
f,
"urn:uuid:\
{:08x}-\
{:04x}-\
{:04x}-\
{:02x}{:02x}-\
{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
self.0.as_bytes()
)
}
}

impl fmt::UpperHex for super::UuidHyphenated {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
hyphenated_write!(
f,
"{:08X}-\
{:04X}-\
{:04X}-\
{:02X}{:02X}-\
{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}",
self.0.as_bytes()
)
}
}

impl<'a> fmt::UpperHex for super::UuidHyphenatedRef<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
hyphenated_write!(
f,
"{:08X}-\
{:04X}-\
{:04X}-\
{:02X}{:02X}-\
{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}",
self.0.as_bytes()
)
}
}

impl fmt::UpperHex for super::UuidSimple {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for byte in self.0.as_bytes() {
write!(f, "{:02X}", byte)?
}

Ok(())
}
}

impl<'a> fmt::UpperHex for super::UuidSimpleRef<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for byte in self.0.as_bytes() {
write!(f, "{:02X}", byte)?
}

Ok(())
}
}

impl fmt::UpperHex for super::UuidUrn {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
hyphenated_write!(
f,
"urn:uuid:\
{:08X}-\
{:04X}-\
{:04X}-\
{:02X}{:02X}-\
{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}",
self.0.as_bytes()
)
}
}

impl<'a> fmt::UpperHex for super::UuidUrnRef<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
hyphenated_write!(
f,
"urn:uuid:\
{:08X}-\
{:04X}-\
{:04X}-\
{:02X}{:02X}-\
{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}",
self.0.as_bytes()
)
}
}

impl From<Uuid> for super::UuidHyphenated {
#[inline]
fn from(f: Uuid) -> Self {
super::UuidHyphenated::from_uuid(f)
}
}

impl<'a> From<&'a Uuid> for super::UuidHyphenatedRef<'a> {
#[inline]
fn from(f: &'a Uuid) -> Self {
super::UuidHyphenatedRef::from_uuid_ref(f)
}
}

impl From<Uuid> for super::UuidSimple {
#[inline]
fn from(f: Uuid) -> Self {
super::UuidSimple::from_uuid(f)
}
}

impl<'a> From<&'a Uuid> for super::UuidSimpleRef<'a> {
#[inline]
fn from(f: &'a Uuid) -> Self {
super::UuidSimpleRef::from_uuid_ref(f)
}
}

impl From<Uuid> for super::UuidUrn {
#[inline]
fn from(f: Uuid) -> Self {
super::UuidUrn::from_uuid(f)
}
}

impl<'a> From<&'a Uuid> for super::UuidUrnRef<'a> {
#[inline]
fn from(f: &'a Uuid) -> Self {
super::UuidUrnRef::from_uuid_ref(f)
}
}

0 comments on commit aa1cc48

Please sign in to comment.