Skip to content

Commit

Permalink
Merge #427
Browse files Browse the repository at this point in the history
427: Breaking API features and refactoring for `0.8` r=kinggoesgaming a=KodrAus

**I'm submitting a(n)** (|feature|refactor|)

# Description

## Modules and Errors

This PR is a broad refactoring of our error types and module layout. The general pattern I've gone for is:

- Define specific error types in submodules. These are currently private.
- Collect these specific error types in an opaque root `Error`. All methods return this single `Error` type so it's easier for consumers to carry `uuid::Error`s in their own code.

It'll also include some implementations for open PRs as we've been discussing. I imagine we'll want to spend time working through these changes :)

I've hidden our `prelude` module for now, because I'm not sure it's something we'll want to stabilize with (it's only got a few bits in it afterall).

## 128bit support

Re-enables support for 128-bit numbers in the form of constructors on `Uuid`, following the pattern that method names without an endian suffix are BE.

## No-std

Refactors our `no-std` support so we always mark the crate as `no-std` so our std imports are always the same. This simplifies our std/core support so we need fewer modules.

## Timestamps

Includes the design proposed in #405 for timestamp support originally implemented by @jonathanstrong.

# Related Issue(s)

- #406

# Related PR(s)

- #405 
- #416

Co-authored-by: Ashley Mannix <[email protected]>
Co-authored-by: Jonathan Strong <[email protected]>
  • Loading branch information
3 people authored Oct 4, 2019
2 parents 195d543 + 2497ac7 commit 1b8308b
Show file tree
Hide file tree
Showing 25 changed files with 1,734 additions and 1,519 deletions.
20 changes: 19 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ matrix:
- os: osx
rust: nightly
- rust: nightly
env:
- LABEL="fmt + cargo-web"
before_script:
- rustup component add rustfmt-preview
- cargo install cargo-web
Expand All @@ -23,13 +25,17 @@ matrix:
- cargo web build --features "v4 wasm-bindgen"
- cargo web build --features "v5 wasm-bindgen"
- rust: beta
env:
- LABEL="cargo-web"
before_script:
- cargo install cargo-web
script:
- cargo web build --features "v3 wasm-bindgen"
- cargo web build --features "v4 wasm-bindgen"
- cargo web build --features "v5 wasm-bindgen"
- rust: stable
env:
- LABEL="clippy + wasm"
before_script:
- rustup component add clippy-preview
- rustup target add wasm32-unknown-unknown
Expand All @@ -38,7 +44,16 @@ 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: stable
env:
- LABEL="no-std"
before_script:
- rustup target add thumbv6m-none-eabi
script:
- cargo build --no-default-features --target thumbv6m-none-eabi
- rust: 1.32.0
env:
- LABEL="msrv"
script:
- cargo test --features "serde std v4"

Expand All @@ -54,14 +69,17 @@ rust:
- nightly

script:
- cargo build --no-default-features
- cargo build --all-features
- cargo build
- cargo test --no-default-features
- cargo test --all-features
- cargo test
- cargo test --features "serde"
- cargo test --features "v1"
- cargo test --features "v3"
- cargo test --features "v4"
- cargo test --features "v5"
- cargo test --features "slog"
- cargo test --features "serde std v1 v3 v4 v5"

sudo: false
5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ status = "actively-developed"
[badges.travis-ci]
repository = "uuid-rs/uuid"

[dependencies.byteorder]
default-features = false
features = ["i128"]
version = "1"

[dependencies.md5]
optional = true
version = "0.6"
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ install:
build: false

test_script:
- cargo build --verbose --all-features
- cargo test --verbose --all-features
2 changes: 1 addition & 1 deletion benches/format_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate test;

use std::io::Write;
use test::Bencher;
use uuid::prelude::*;
use uuid::Uuid;

#[bench]
fn bench_hyphen(b: &mut Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion benches/invalid_parse_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
extern crate test;

use test::Bencher;
use uuid::prelude::*;
use uuid::Uuid;

#[bench]
fn bench_parse_invalid_strings(b: &mut Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion benches/serde_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde_json;
extern crate test;

use test::Bencher;
use uuid::prelude::*;
use uuid::Uuid;

#[bench]
fn bench_json_encode(b: &mut Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion benches/valid_parse_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
extern crate test;

use test::Bencher;
use uuid::prelude::*;
use uuid::Uuid;

#[bench]
fn bench_parse_valid_strings(b: &mut Bencher) {
Expand Down
68 changes: 0 additions & 68 deletions src/adapter/core_support/mod.rs

This file was deleted.

59 changes: 56 additions & 3 deletions src/adapter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
//! [`Uuid`]: ../struct.Uuid.html

use crate::prelude::*;
use core::str;

mod core_support;
use crate::std::{fmt, str};

#[cfg(feature = "serde")]
pub mod compact;
Expand Down Expand Up @@ -844,6 +842,61 @@ impl<'a> UrnRef<'a> {
}
}

macro_rules! impl_adapter_traits {
($($T:ident<$($a:lifetime),*>),+) => {$(
impl<$($a),*> fmt::Display for $T<$($a),*> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::LowerHex::fmt(self, f)
}
}

impl<$($a),*> fmt::LowerHex for $T<$($a),*> {
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; $T::LENGTH]))
}
}

impl<$($a),*> fmt::UpperHex for $T<$($a),*> {
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; $T::LENGTH]))
}
}

impl_adapter_from!($T<$($a),*>);
)+}
}

macro_rules! impl_adapter_from {
($T:ident<>) => {
impl From<Uuid> for $T {
#[inline]
fn from(f: Uuid) -> Self {
$T::from_uuid(f)
}
}
};
($T:ident<$a:lifetime>) => {
impl<$a> From<&$a Uuid> for $T<$a> {
#[inline]
fn from(f: &$a Uuid) -> Self {
$T::from_uuid_ref(f)
}
}
};
}

impl_adapter_traits! {
Hyphenated<>,
HyphenatedRef<'a>,
Simple<>,
SimpleRef<'a>,
Urn<>,
UrnRef<'a>
}

#[cfg(test)]
mod tests {
use crate::prelude::*;
Expand Down
Loading

0 comments on commit 1b8308b

Please sign in to comment.