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

add into_any_send_sync(), bump .travis.yml #4

Merged
merged 1 commit into from
Oct 16, 2018
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
42 changes: 27 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
language: rust
rust: nightly
cache:
- cargo
# cache:
# - apt
# - cargo
git:
depth: 1
depth: 10

addons:
apt:
Expand All @@ -12,23 +13,23 @@ addons:

env:
global:
- FMT_VERSION=nightly-2018-07-30
- CLIPPY_VERSION=nightly-2018-07-30
- DOCS_RS_VERSION=nightly-2018-07-17 # should be 2018-06-03 but failing due to lack of trivial_bounds feature # https://github.com/onur/docs.rs/blob/32102ce458b34f750ef190182116d9583491a64b/Vagrantfile#L50
- FMT_VERSION=nightly-2018-10-14
- CLIPPY_VERSION=nightly-2018-10-14
- DOCS_RS_VERSION=nightly-2018-10-14 # should be 2018-06-03 but failing due to lack of trivial_bounds feature # https://github.com/onur/docs.rs/blob/32102ce458b34f750ef190182116d9583491a64b/Vagrantfile#L50

matrix:
include:
- os: linux
dist: precise
env: BUILD="" RUN="x86_64-unknown-linux-gnu i686-unknown-linux-gnu x86_64-unknown-linux-musl i686-unknown-linux-musl" RUSTFLAGS_VARIATIONS=";" DIST="precise" # ;-Cpanic=abort;-Clinker=gold -Zlinker-flavor=ld;-Clinker=rust-lld -Zlinker-flavor=ld.lld;
env: BUILD="" RUN="x86_64-unknown-linux-gnu i686-unknown-linux-gnu x86_64-unknown-linux-musl i686-unknown-linux-musl" RUSTFLAGS_VARIATIONS=";" DIST="precise" # ;-Cpanic=abort;-Clinker=gold
- os: linux
dist: trusty
sudo: false
env: BUILD="" RUN="x86_64-unknown-linux-gnu i686-unknown-linux-gnu x86_64-unknown-linux-musl i686-unknown-linux-musl" RUSTFLAGS_VARIATIONS=";" DIST="trusty" # ;-Cpanic=abort;-Clinker=gold -Zlinker-flavor=ld;-Clinker=rust-lld -Zlinker-flavor=ld.lld;
env: BUILD="" RUN="x86_64-unknown-linux-gnu i686-unknown-linux-gnu x86_64-unknown-linux-musl i686-unknown-linux-musl" RUSTFLAGS_VARIATIONS=";" DIST="trusty" # ;-Cpanic=abort;-Clinker=gold
- os: linux
dist: trusty
sudo: required # https://docs.travis-ci.com/user/reference/overview/
env: BUILD="" RUN="x86_64-unknown-linux-gnu i686-unknown-linux-gnu x86_64-unknown-linux-musl i686-unknown-linux-musl" RUSTFLAGS_VARIATIONS=";" DIST="trusty" # ;-Cpanic=abort;-Clinker=gold -Zlinker-flavor=ld;-Clinker=rust-lld -Zlinker-flavor=ld.lld;
env: BUILD="" RUN="x86_64-unknown-linux-gnu i686-unknown-linux-gnu x86_64-unknown-linux-musl i686-unknown-linux-musl" RUSTFLAGS_VARIATIONS=";" DIST="trusty" # ;-Cpanic=abort;-Clinker=gold
- os: osx
osx_image: xcode6.4 # https://docs.travis-ci.com/user/reference/osx/
env: BUILD="x86_64-unknown-linux-musl i686-unknown-linux-musl" RUN="x86_64-apple-darwin i686-apple-darwin" RUSTFLAGS_VARIATIONS=";" # https://github.com/rust-lang/rust/pull/49219 ;-Cpanic=abort
Expand All @@ -41,6 +42,12 @@ matrix:

before_script: |
( set -o errexit;set -o pipefail; set -o xtrace;set -o nounset;
if [ "$TRAVIS_OS_NAME" = "linux" -a "${DIST-}" = "precise" ]; then
# Bump libstdc++6 for libLLVM-8svn.so which requires GLIBCXX_3.4.17 https://askubuntu.com/questions/575505/glibcxx-3-4-20-not-found-how-to-fix-this-error
sudo -E add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo -E apt-get update
sudo -E apt-get -yq --no-install-suggests --no-install-recommends $(travis_apt_get_options) install libstdc++6-4.7-dev
fi
for TARGET in $BUILD $RUN; do [ "$TARGET" = $(rustup target list | grep default | grep -o -e '^[^ ]\+') ] || travis_retry rustup target add "$TARGET"; done
travis_retry rustup toolchain add $FMT_VERSION
travis_retry rustup toolchain add $CLIPPY_VERSION
Expand All @@ -52,22 +59,27 @@ before_script: |
script: |
( set -o errexit;set -o pipefail; set -o xtrace;set -o nounset;
cargo +$FMT_VERSION fmt -- --check
cargo +$CLIPPY_VERSION clippy --lib --tests -- -D warnings
RUSTFLAGS="-C target-cpu=native" cargo +$CLIPPY_VERSION clippy --all-targets --all-features -- -D warnings
OLD_IFS=$IFS IFS=";"; for RUSTFLAGS in $RUSTFLAGS_VARIATIONS; do ( IFS=$OLD_IFS
export RUSTFLAGS
for TARGET in $BUILD $RUN; do (
[ \( "$TRAVIS_OS_NAME" = "osx" -o \( "$TRAVIS_OS_NAME" = "linux" -a "${DIST-}" = "precise" \) \) -a \( "$TARGET" = "x86_64-unknown-linux-musl" -o "$TARGET" = "i686-unknown-linux-musl" \) ] && RUSTFLAGS="$RUSTFLAGS -C linker=rust-lld -Z linker-flavor=ld.lld"
cargo build --verbose --target "$TARGET" --lib --tests
cargo build --verbose --target "$TARGET" --lib --tests --release
cargo build --verbose --target "$TARGET" --all-targets --all-features
RUSTFLAGS="$RUSTFLAGS -C target-cpu=native" cargo build --verbose --target "$TARGET" --all-targets --all-features --release
); done
for TARGET in $RUN; do (
[ \( "$TRAVIS_OS_NAME" = "osx" -o \( "$TRAVIS_OS_NAME" = "linux" -a "${DIST-}" = "precise" \) \) -a \( "$TARGET" = "x86_64-unknown-linux-musl" -o "$TARGET" = "i686-unknown-linux-musl" \) ] && RUSTFLAGS="$RUSTFLAGS -C linker=rust-lld -Z linker-flavor=ld.lld"
RUST_BACKTRACE=full cargo test --target "$TARGET"
RUST_BACKTRACE=full cargo test --target "$TARGET" --release
RUST_BACKTRACE=full cargo test --target "$TARGET" --all-features
RUSTFLAGS="$RUSTFLAGS -C target-cpu=native" RUST_BACKTRACE=full cargo test --target "$TARGET" --all-features --release
RUSTFLAGS="$RUSTFLAGS -C target-cpu=native" RUST_BACKTRACE=full cargo bench --target "$TARGET" --all-features
[ ! -d examples ] || for example in examples/*; do example=${example##*/}; (
RUST_BACKTRACE=full cargo run --target "$TARGET" --example ${example%.*} --all-features
RUSTFLAGS="$RUSTFLAGS -C target-cpu=native" RUST_BACKTRACE=full cargo run --target "$TARGET" --example ${example%.*} --all-features --release
); done
); done
); done; IFS=$OLD_IFS
for TARGET in $BUILD $RUN; do
cargo +$DOCS_RS_VERSION doc --no-deps --target "$TARGET" --release &>/dev/null
cargo +$DOCS_RS_VERSION doc --no-deps --target "$TARGET" --all-features --release &>/dev/null
done
)

Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ maintenance = { status = "actively-developed" }
[dependencies]
serde = "1.0"
erased-serde = "0.3"
metatype = "0.1.1"
relative = "0.1.2"
metatype = { version = "0.1.1" } #, path = "../metatype" }
relative = { version = "0.1.2" } #, path = "../relative" }

[dev-dependencies]
serde_closure = "0.1.3"
serde_derive = "1.0"
serde_json = "1.0"
bincode = "1.0"
serde_closure = { version = "0.1.3" } #, path = "../serde_closure" }

[[test]]
name = "test"
Expand Down
50 changes: 49 additions & 1 deletion src/convenience.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ impl Box<Any> {
self.0.into_any()
}
}
impl Box<Any + Send> {
/// Convert into a `std::boxed::Box<dyn std::any::Any + Send>`.
pub fn into_any_send(self) -> boxed::Box<any::Any + Send> {
self.0.into_any_send()
}
}
impl Box<Any + Sync> {
/// Convert into a `std::boxed::Box<dyn std::any::Any + Sync>`.
pub fn into_any_sync(self) -> boxed::Box<any::Any + Sync> {
self.0.into_any_sync()
}
}
impl Box<Any + Send + Sync> {
/// Convert into a `std::boxed::Box<dyn std::any::Any + Send + Sync>`.
pub fn into_any_send_sync(self) -> boxed::Box<any::Any + Send + Sync> {
self.0.into_any_send_sync()
}
}
impl<
T: Serialize + Deserialize + ?Sized + marker::Unsize<U>,
U: Serialize + Deserialize + ?Sized,
Expand Down Expand Up @@ -336,8 +354,20 @@ pub trait Any: Serialize + Deserialize + any::Any {
fn as_any(&self) -> &any::Any;
/// Convert to a `&mut std::any::Any`.
fn as_any_mut(&mut self) -> &mut any::Any;
/// Convert to a `std::boxed::Box<std::any::Any>`.
/// Convert to a `std::boxed::Box<dyn std::any::Any>`.
fn into_any(self: boxed::Box<Self>) -> boxed::Box<any::Any>;
/// Convert to a `std::boxed::Box<dyn std::any::Any + Send>`.
fn into_any_send(self: boxed::Box<Self>) -> boxed::Box<any::Any + Send>
where
Self: Send;
/// Convert to a `std::boxed::Box<dyn std::any::Any + Sync>`.
fn into_any_sync(self: boxed::Box<Self>) -> boxed::Box<any::Any + Sync>
where
Self: Sync;
/// Convert to a `std::boxed::Box<dyn std::any::Any + Send + Sync>`.
fn into_any_send_sync(self: boxed::Box<Self>) -> boxed::Box<any::Any + Send + Sync>
where
Self: Send + Sync;
}
impl<T: Serialize + Deserialize + any::Any> Any for T {
fn as_any(&self) -> &any::Any {
Expand All @@ -349,6 +379,24 @@ impl<T: Serialize + Deserialize + any::Any> Any for T {
fn into_any(self: boxed::Box<Self>) -> boxed::Box<any::Any> {
self
}
fn into_any_send(self: boxed::Box<Self>) -> boxed::Box<any::Any + Send>
where
Self: Send,
{
self
}
fn into_any_sync(self: boxed::Box<Self>) -> boxed::Box<any::Any + Sync>
where
Self: Sync,
{
self
}
fn into_any_send_sync(self: boxed::Box<Self>) -> boxed::Box<any::Any + Send + Sync>
where
Self: Send + Sync,
{
self
}
}

/// A convenience trait implemented on all (de)serializable implementors of [std::error::Error].
Expand Down
13 changes: 9 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
unsize,
specialization,
trivial_bounds,
fnbox,
fnbox
)]
#![warn(
missing_copy_implementations,
Expand All @@ -98,9 +98,13 @@
unused_import_braces,
unused_qualifications,
unused_results,
clippy::pedantic
)] // from https://github.com/rust-unofficial/patterns/blob/master/anti_patterns/deny-warnings.md
#![cfg_attr(feature = "cargo-clippy", warn(clippy_pedantic))]
#![cfg_attr(feature = "cargo-clippy", allow(inline_always, doc_markdown))]
#![allow(
where_clauses_object_safety,
clippy::inline_always,
clippy::doc_markdown
)]

extern crate erased_serde;
extern crate metatype;
Expand Down Expand Up @@ -501,7 +505,8 @@ impl<'de, T: Deserialize + ?Sized> serde::de::DeserializeSeed<'de> for Deseriali
let mut x = self.0;
unsafe {
(&mut *x).deserialize_erased(&mut erased_serde::Deserializer::erase(deserializer))
}.map(|()| x)
}
.map(|()| x)
.map_err(serde::de::Error::custom)
}
}
Expand Down
32 changes: 27 additions & 5 deletions tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
#![feature(unboxed_closures)]
#![warn(
missing_copy_implementations,
missing_debug_implementations,
// missing_docs,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
unused_qualifications,
unused_results,
clippy::pedantic
)] // from https://github.com/rust-unofficial/patterns/blob/master/anti_patterns/deny-warnings.md
#![allow(
where_clauses_object_safety,
clippy::inline_always,
clippy::doc_markdown,
clippy::unseparated_literal_suffix
)]

#[macro_use]
extern crate serde_derive;
Expand Down Expand Up @@ -90,9 +107,11 @@ fn main() {
*Box::<any::Any>::downcast::<usize>(
Box::<any::Any>::downcast::<serde_traitobject::Box<serde_traitobject::Any>>(
i.into_any()
).unwrap()
)
.unwrap()
.into_any()
).unwrap(),
)
.unwrap(),
987_654_321
);
assert_eq!(**j, "abc");
Expand Down Expand Up @@ -146,7 +165,8 @@ fn main() {
let a1 = serde_json::to_string(
&(serde_traitobject::Box::new(78u8)
as serde_traitobject::Box<serde_traitobject::Debug>),
).unwrap();
)
.unwrap();
let a1r: Result<serde_traitobject::Box<serde_traitobject::Debug>, _> =
serde_json::from_str(&a1);
assert!(a1r.is_ok());
Expand All @@ -156,7 +176,8 @@ fn main() {
let a1 = bincode::serialize(
&(serde_traitobject::Box::new(78u8)
as serde_traitobject::Box<serde_traitobject::Debug>),
).unwrap();
)
.unwrap();
let a1: Result<serde_traitobject::Box<serde_traitobject::Any>, _> =
bincode::deserialize(&a1);
assert!(a1.is_err());
Expand Down Expand Up @@ -202,7 +223,8 @@ fn main() {
"SERDE_TRAITOBJECT_SPAWNED",
serde_json::to_string(&(&original, bincode::serialize(&original).unwrap()))
.unwrap(),
).output()
)
.output()
.unwrap();
if !output.status.success() {
panic!("{}: {:?}", i, output);
Expand Down