Skip to content

Commit

Permalink
0.2.0: make it work on the beta/stable channels.
Browse files Browse the repository at this point in the history
This is a [breaking-change]. Traits being mopafied formerly needed to
extend `std::any::Any`; now they need to extend `mopa::Any`.

Users of `#![no_std]` will now need to enable the `no_std` feature on
this crate.

Users of this library formerly also needed `#![feature(core)]` on the
crate; this is necessary no longer, because mopa works on Rust stable
and beta.
  • Loading branch information
chris-morgan committed May 13, 2015
1 parent c1bbafd commit 24f6c2d
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 79 deletions.
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
language: rust
rust:
- nightly
- beta
#env:
# global:
# - secure: TODO
#script:
# - cargo build --verbose
# - cargo test --verbose
# - cargo doc --verbose
script:
- if [[ "$(rustc --version)" =~ -(dev|nightly) ]]; then cargo test --features no_std; else ! cargo test --features no_std; fi
- cargo test
# - cargo doc
#after_script:
# - ln -s target/doc doc
# - curl http://www.rust-ci.org/artifacts/put?t=$RUSTCI_TOKEN | sh
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mopa"
version = "0.1.8"
version = "0.2.0"
authors = ["Chris Morgan <[email protected]>"]
description = "My Own Personal Any: get your own Any with additional functionality"
#documentation =
Expand All @@ -9,3 +9,6 @@ repository = "https://github.com/chris-morgan/mopa"
readme = "README.md"
keywords = ["any", "macro"]
license = "MIT/Apache-2.0"

[features]
no_std = []
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mopa 0.1.8
mopa 0.2.0
==========

[![Build Status](https://travis-ci.org/chris-morgan/mopa.svg?branch=master)](https://travis-ci.org/chris-morgan/mopa)
Expand Down Expand Up @@ -27,11 +27,11 @@ it. Fortunately now you can *mopafy* `Person` in three simple steps:
1. Add the `mopa` crate to your `Cargo.toml` as usual and your crate root like so:

```rust,ignore
#[macro_use] #[no_link]
#[macro_use]
extern crate mopa;
```

2. Make `Any` a supertrait of `Person`;
2. Make `Any` (`mopa::Any`, not `std::any::Any`) a supertrait of `Person`;

3. `mopafy!(Person);`.

Expand All @@ -42,11 +42,9 @@ Oh, by the way, it was actually the person on the bear’s plate. There wasn’t
`Person`’s plate after all.

```rust
#[macro_use] #[no_link]
#[macro_use]
extern crate mopa;

use std::any::Any;

struct Bear {
// This might be a pretty fat bear.
fatness: u16,
Expand All @@ -58,7 +56,7 @@ impl Bear {
}
}

trait Person: Any {
trait Person: mopa::Any {
fn panic(&self);
fn yell(&self) { println!("Argh!"); }
fn sleep(&self);
Expand Down
53 changes: 34 additions & 19 deletions examples/no_std.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,47 @@
#![feature(lang_items, start, core, alloc, no_std)]
#![no_std]
// This example depends on the no_std feature being enabled on the crate;
// without it, we have to go and chop everything off so that it can compile.
// If you are basing something off this example, please note that all the `feature = "no_std"`
// cfg-gating is a workaround for Cargo until https://github.com/rust-lang/cargo/issues/1570 lands.
// Do not include it if you copy any code.

#[macro_use] #[no_link]
#![cfg_attr(feature = "no_std", feature(lang_items, start, core, alloc, no_std))]
#![cfg_attr(feature = "no_std", no_std)]

#[cfg(not(feature = "no_std"))]
fn main() { }

#[cfg(feature = "no_std")]
#[macro_use]
extern crate mopa;

#[cfg(feature = "no_std")]
extern crate core;
#[cfg(feature = "no_std")]
extern crate alloc;

trait Panic { fn panic(&self) { } }
#[cfg(feature = "no_std")]
mod silly_wrapper_to_save_writing_the_whole_cfg_incantation_on_every_item {
trait Panic { fn panic(&self) { } }

trait PanicAny: Panic + core::any::Any { }
trait PanicAny: Panic + ::mopa::Any { }

mopafy!(PanicAny, core = core, alloc = alloc);
mopafy!(PanicAny, core = core, alloc = alloc);

impl Panic for i32 { }
impl Panic for i32 { }

impl<T: Panic + core::any::Any + 'static> PanicAny for T { }
impl<T: Panic + ::mopa::Any + 'static> PanicAny for T { }

#[start]
fn start(_argc: isize, _argv: *const *const u8) -> isize {
let p: &PanicAny = &2;
if p.is::<i32>() {
0
} else {
1
#[start]
fn start(_argc: isize, _argv: *const *const u8) -> isize {
let p: &PanicAny = &2;
if p.is::<i32>() {
0
} else {
1
}
}
}

#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] extern fn panic_fmt() {}
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] extern fn panic_fmt() {}
}
54 changes: 35 additions & 19 deletions examples/no_std_or_alloc.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,48 @@
#![feature(lang_items, start, core, libc, no_std)]
#![no_std]
// This example depends on the no_std feature being enabled on the crate;
// without it, we have to go and chop everything off so that it can compile.
// If you are basing something off this example, please note that all the `feature = "no_std"`
// cfg-gating is a workaround for Cargo until https://github.com/rust-lang/cargo/issues/1570 lands.
// Do not include it if you copy any code.

#[macro_use] #[no_link]

#![cfg_attr(feature = "no_std", feature(lang_items, start, core, libc, no_std))]
#![cfg_attr(feature = "no_std", no_std)]

#[cfg(not(feature = "no_std"))]
fn main() { }

#[cfg(feature = "no_std")]
#[macro_use]
extern crate mopa;

#[cfg(feature = "no_std")]
extern crate core;
#[cfg(feature = "no_std")]
extern crate libc;

trait Panic { fn panic(&self) { } }
#[cfg(feature = "no_std")]
mod silly_wrapper_to_save_writing_the_whole_cfg_incantation_on_every_item {
trait Panic { fn panic(&self) { } }

trait PanicAny: Panic + core::any::Any { }
trait PanicAny: Panic + ::mopa::Any { }

mopafy!(PanicAny, core = core);
mopafy!(PanicAny, core = core);

impl Panic for i32 { }
impl Panic for i32 { }

impl<T: Panic + core::any::Any + 'static> PanicAny for T { }
impl<T: Panic + ::mopa::Any + 'static> PanicAny for T { }

#[start]
fn start(_argc: isize, _argv: *const *const u8) -> isize {
let p: &PanicAny = &2;
if p.is::<i32>() {
0
} else {
1
#[start]
fn start(_argc: isize, _argv: *const *const u8) -> isize {
let p: &PanicAny = &2;
if p.is::<i32>() {
0
} else {
1
}
}
}

#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] extern fn panic_fmt() {}
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] extern fn panic_fmt() {}
}
6 changes: 2 additions & 4 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#![feature(core)]

#[macro_use] #[no_link]
#[macro_use]
extern crate mopa;

use std::any::Any;
use mopa::Any;

trait PanicAny: Any { }

Expand Down
Loading

0 comments on commit 24f6c2d

Please sign in to comment.