Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/2018 edition #388

Merged
merged 17 commits into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ matrix:
- cargo build --target wasm32-unknown-unknown --features "v3 wasm-bindgen"
- cargo build --target wasm32-unknown-unknown --features "v4 wasm-bindgen"
- cargo build --target wasm32-unknown-unknown --features "v5 wasm-bindgen"
- rust: 1.22.0
- rust: 1.31.0
script:
- cargo test --features "serde std v4"

Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ authors = [
]
description = "A library to generate and parse UUIDs."
documentation = "https://docs.rs/uuid"
edition = "2018"
exclude = [
".github/**",
".travis.yml",
Expand Down Expand Up @@ -58,6 +59,7 @@ version = "0.6"

[dependencies.serde]
default-features = false
features = [ "serde_derive" ]
optional = true
version = "1.0.56"

Expand Down Expand Up @@ -85,11 +87,11 @@ version = "1.0.56"
default = ["std"]
guid = ["winapi"]
std = []
stdweb = [ "rand/stdweb" ]
v1 = []
v3 = ["md5"]
v4 = ["rand"]
v5 = ["sha1"]
stdweb = ["rand/stdweb"]
wasm-bindgen = ["rand/wasm-bindgen"]

# since rust 1.26.0
Expand Down
2 changes: 1 addition & 1 deletion README.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[![Latest Version](https://img.shields.io/crates/v/uuid.svg)](https://crates.io/crates/uuid)
[![Join the chat at https://gitter.im/uuid-rs/Lobby](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/uuid-rs/Lobby?utm_source=badge&utm_medium=badge&utm_content=badge)
![Minimum rustc version](https://img.shields.io/badge/rustc-1.22.0+-yellow.svg)
![Minimum rustc version](https://img.shields.io/badge/rustc-1.31.0+-yellow.svg)
{{badges}}

---
Expand Down
1 change: 0 additions & 1 deletion benches/format_str.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![feature(test)]
extern crate test;
extern crate uuid;

use std::io::Write;
use test::Bencher;
Expand Down
6 changes: 0 additions & 6 deletions benches/invalid_parse_str.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#![feature(test)]
#[cfg(feature = "slog")]
#[macro_use]
extern crate slog;
extern crate test;
extern crate uuid;

#[cfg(feature = "slog")]
use slog::Drain;
use test::Bencher;
use uuid::prelude::*;

Expand Down
6 changes: 1 addition & 5 deletions benches/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#![feature(test)]
#[cfg(feature = "slog")]
#[macro_use]
extern crate slog;
extern crate test;
extern crate uuid;

#[cfg(feature = "slog")]
pub mod slog_support;
5 changes: 2 additions & 3 deletions benches/serde_support.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#![cfg(feature = "serde")]
#![feature(test)]

extern crate bincode;
extern crate serde_json;
use bincode;
use serde_json;
extern crate test;
extern crate uuid;

use test::Bencher;
use uuid::prelude::*;
Expand Down
6 changes: 0 additions & 6 deletions benches/slog_support/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
#[cfg(feature = "slog")]
// #[macro_use]
// extern crate slog;
// extern crate test;
extern crate uuid;

pub mod parse_str;
14 changes: 7 additions & 7 deletions benches/slog_support/parse_str.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use test::Bencher;
use uuid::prelude::*;
extern crate test;

#[bench]
#[cfg(feature = "slog")]
pub fn bench_log_discard_kv(b: &mut Bencher) {
let u1 = Uuid::parse_str("F9168C5E-CEB2-4FAB-B6BF-329BF39FA1E4").unwrap();
let root = ::slog::Logger::root(::slog::Drain::fuse(::slog::Discard), o!());
// let root = ::slog::Logger::root(::slog::Discard.fuse(), o!());
pub fn bench_log_discard_kv(b: &mut test::Bencher) {
let u1 =
uuid::Uuid::parse_str("F9168C5E-CEB2-4FAB-B6BF-329BF39FA1E4").unwrap();
let root =
slog::Logger::root(::slog::Drain::fuse(::slog::Discard), slog::o!());

b.iter(|| {
#[cfg(feature = "slog")]
crit!(root, "test"; "u1" => u1);
slog::crit!(root, "test"; "u1" => u1);
});
}
7 changes: 1 addition & 6 deletions benches/valid_parse_str.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#![feature(test)]
#[cfg(feature = "slog")]
#[macro_use]
extern crate slog;

extern crate test;
extern crate uuid;

#[cfg(feature = "slog")]
use slog::Drain;
use test::Bencher;
use uuid::prelude::*;

Expand Down
41 changes: 18 additions & 23 deletions src/adapter/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,45 @@
//!
//! [`Uuid`]: ../../struct.Uuid.html

use serde::{Deserialize, Deserializer, Serialize, Serializer};

use prelude::*;

/// Serializer for a [`Uuid`] into a `[u8; 16]`
///
/// [`Uuid`]: ../../struct.Uuid.html
pub fn serialize<S: Serializer>(
u: &Uuid,
serializer: S,
) -> Result<S::Ok, S::Error> {
u.as_bytes().serialize(serializer)
pub fn serialize<S>(u: &crate::Uuid, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serde::Serialize::serialize(u.as_bytes(), serializer)
}

/// Deserializer from a `[u8; 16]` into a [`Uuid`]
///
/// [`Uuid`]: ../../struct.Uuid.html
pub fn deserialize<'de, D: Deserializer<'de>>(
deserializer: D,
) -> Result<Uuid, D::Error> {
let bytes = <[u8; 16]>::deserialize(deserializer)?;
pub fn deserialize<'de, D>(deserializer: D) -> Result<crate::Uuid, D::Error>
where
D: serde::Deserializer<'de>,
{
let bytes: [u8; 16] = serde::Deserialize::deserialize(deserializer)?;

Ok(Uuid::from_bytes(bytes))
Ok(crate::Uuid::from_bytes(bytes))
}

#[cfg(test)]
mod tests {
use serde_test;

use prelude::*;

#[derive(Serialize, Debug, Deserialize, PartialEq)]
struct UuidContainer {
#[serde(with = "super")]
u: Uuid,
}
use serde_test;

#[test]
fn test_serialize_compact() {
#[derive(serde::Serialize, Debug, serde::Deserialize, PartialEq)]
struct UuidContainer {
#[serde(with = "super")]
u: crate::Uuid,
}
use serde_test::Configure;

let uuid_bytes = b"F9168C5E-CEB2-4F";
let container = UuidContainer {
u: Uuid::from_slice(uuid_bytes).unwrap(),
u: crate::Uuid::from_slice(uuid_bytes).unwrap(),
};

// more complex because of the struct wrapping the actual UUID
Expand Down
38 changes: 19 additions & 19 deletions src/adapter/core_support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,124 +9,124 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

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

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

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

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

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

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

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

impl fmt::LowerHex for super::Hyphenated {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.encode_lower(&mut [0; Self::LENGTH]))
}
}

impl<'a> fmt::LowerHex for super::HyphenatedRef<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// TODO: Self doesn't work https://github.com/rust-lang/rust/issues/52808
f.write_str(self.encode_lower(&mut [0; super::HyphenatedRef::LENGTH]))
}
}

impl fmt::LowerHex for super::Simple {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.encode_lower(&mut [0; Self::LENGTH]))
}
}

impl<'a> fmt::LowerHex for super::SimpleRef<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// TODO: Self doesn't work https://github.com/rust-lang/rust/issues/52808
f.write_str(self.encode_lower(&mut [0; super::SimpleRef::LENGTH]))
}
}

impl fmt::LowerHex for super::Urn {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.encode_lower(&mut [0; Self::LENGTH]))
}
}

impl<'a> fmt::LowerHex for super::UrnRef<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// TODO: Self doesn't work https://github.com/rust-lang/rust/issues/52808
f.write_str(self.encode_lower(&mut [0; super::UrnRef::LENGTH]))
}
}

impl fmt::UpperHex for super::Hyphenated {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.encode_upper(&mut [0; Self::LENGTH]))
}
}

impl<'a> fmt::UpperHex for super::HyphenatedRef<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// TODO: Self doesn't work https://github.com/rust-lang/rust/issues/52808
f.write_str(self.encode_upper(&mut [0; super::HyphenatedRef::LENGTH]))
}
}

impl fmt::UpperHex for super::Simple {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.encode_upper(&mut [0; Self::LENGTH]))
}
}

impl<'a> fmt::UpperHex for super::SimpleRef<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// TODO: Self doesn't work https://github.com/rust-lang/rust/issues/52808
f.write_str(self.encode_upper(&mut [0; super::SimpleRef::LENGTH]))
}
}

impl fmt::UpperHex for super::Urn {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.encode_upper(&mut [0; Self::LENGTH]))
}
}

impl<'a> fmt::UpperHex for super::UrnRef<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// TODO: Self doesn't work https://github.com/rust-lang/rust/issues/52808
f.write_str(self.encode_upper(&mut [0; super::UrnRef::LENGTH]))
}
Expand Down
Loading