Skip to content

replaced custom_derive with macro-attr #14

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ exclude = [

[features]
default = ["std"]
std = ["custom_derive/std"]
std = ["macro-attr/std"]

[dependencies]
custom_derive = { version = "0.1.5", default-features = false }
macro-attr = { version = "0.2.0", default-features = false }

[dev-dependencies]
quickcheck = "0.2.21, < 0.2.25"
Expand Down
84 changes: 42 additions & 42 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,24 +224,24 @@ macro_rules! IntoInner {
};
}

custom_derive!{
macro_attr!{
/**
A general error enumeration that subsumes all other conversion errors.

This exists primarily as a "catch-all" for reliably unifying various different kinds of conversion errors.
*/
#[derive(
Copy, Clone, Eq, PartialEq, Ord, PartialOrd,
IntoInner, DummyDebug, FromNoError,
EnumDesc(
IntoInner!, DummyDebug!, FromNoError!,
EnumDesc!(
NegOverflow => "conversion resulted in negative overflow",
PosOverflow => "conversion resulted in positive overflow",
Unrepresentable => "could not convert unrepresentable value",
),
FromName(Unrepresentable),
FromName(NegOverflow),
FromName(PosOverflow),
FromRemap(RangeError(NegOverflow, PosOverflow))
FromName!(Unrepresentable),
FromName!(NegOverflow),
FromName!(PosOverflow),
FromRemap!(RangeError(NegOverflow, PosOverflow))
)]
pub enum GeneralError<T> {
/// Input was too negative for the target type.
Expand All @@ -268,26 +268,26 @@ impl<T> From<FloatError<T>> for GeneralError<T> {
}
}

custom_derive! {
macro_attr! {
/**
A general error enumeration that subsumes all other conversion errors, but discards all input payloads the errors may be carrying.

This exists primarily as a "catch-all" for reliably unifying various different kinds of conversion errors, and between different input types.
*/
#[derive(
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug,
FromNoError,
EnumDesc(
FromNoError!,
EnumDesc!(
NegOverflow => "conversion resulted in negative overflow",
PosOverflow => "conversion resulted in positive overflow",
Unrepresentable => "could not convert unrepresentable value",
),
FromName(Unrepresentable<T>),
FromName(NegOverflow<T>),
FromName(PosOverflow<T>),
FromRemap(RangeErrorKind(NegOverflow, PosOverflow)),
FromRemap(RangeError<T>(NegOverflow, PosOverflow)),
FromRemap(GeneralError<T>(NegOverflow, PosOverflow, Unrepresentable))
FromName!(Unrepresentable<T>),
FromName!(NegOverflow<T>),
FromName!(PosOverflow<T>),
FromRemap!(RangeErrorKind(NegOverflow, PosOverflow)),
FromRemap!(RangeError<T>(NegOverflow, PosOverflow)),
FromRemap!(GeneralError<T>(NegOverflow, PosOverflow, Unrepresentable))
)]
pub enum GeneralErrorKind {
/// Input was too negative for the target type.
Expand Down Expand Up @@ -334,51 +334,51 @@ impl Error for NoError {
}
}

custom_derive! {
macro_attr! {
/// Indicates that the conversion failed because the value was not representable.
#[derive(
Copy, Clone, Eq, PartialEq, Ord, PartialOrd,
IntoInner, DummyDebug, FromNoError,
Desc("could not convert unrepresentable value")
IntoInner!, DummyDebug!, FromNoError!,
Desc!("could not convert unrepresentable value")
)]
pub struct Unrepresentable<T>(pub T);
}

custom_derive! {
macro_attr! {
/// Indicates that the conversion failed due to a negative overflow.
#[derive(
Copy, Clone, Eq, PartialEq, Ord, PartialOrd,
IntoInner, DummyDebug, FromNoError,
Desc("conversion resulted in negative overflow")
IntoInner!, DummyDebug!, FromNoError!,
Desc!("conversion resulted in negative overflow")
)]
pub struct NegOverflow<T>(pub T);
}

custom_derive! {
macro_attr! {
/// Indicates that the conversion failed due to a positive overflow.
#[derive(
Copy, Clone, Eq, PartialEq, Ord, PartialOrd,
IntoInner, DummyDebug, FromNoError,
Desc("conversion resulted in positive overflow")
IntoInner!, DummyDebug!, FromNoError!,
Desc!("conversion resulted in positive overflow")
)]
pub struct PosOverflow<T>(pub T);
}

custom_derive! {
macro_attr! {
/**
Indicates that a conversion from a floating point type failed.
*/
#[derive(
Copy, Clone, Eq, PartialEq, Ord, PartialOrd,
IntoInner, DummyDebug, FromNoError,
EnumDesc(
IntoInner!, DummyDebug!, FromNoError!,
EnumDesc!(
NegOverflow => "conversion resulted in negative overflow",
PosOverflow => "conversion resulted in positive overflow",
NotANumber => "conversion target does not support not-a-number",
),
FromName(NegOverflow),
FromName(PosOverflow),
FromRemap(RangeError(NegOverflow, PosOverflow))
FromName!(NegOverflow),
FromName!(PosOverflow),
FromRemap!(RangeError(NegOverflow, PosOverflow))
)]
pub enum FloatError<T> {
/// Input was too negative for the target type.
Expand All @@ -392,19 +392,19 @@ custom_derive! {
}
}

custom_derive! {
macro_attr! {
/**
Indicates that a conversion failed due to a range error.
*/
#[derive(
Copy, Clone, Eq, PartialEq, Ord, PartialOrd,
IntoInner, DummyDebug, FromNoError,
EnumDesc(
IntoInner!, DummyDebug!, FromNoError!,
EnumDesc!(
NegOverflow => "conversion resulted in negative overflow",
PosOverflow => "conversion resulted in positive overflow",
),
FromName(NegOverflow),
FromName(PosOverflow)
FromName!(NegOverflow),
FromName!(PosOverflow)
)]
pub enum RangeError<T> {
/// Input was too negative for the target type.
Expand All @@ -415,22 +415,22 @@ custom_derive! {
}
}

custom_derive! {
macro_attr! {
/**
Indicates that a conversion failed due to a range error.

This is a variant of `RangeError` that does not retain the input value which caused the error. It exists to help unify some utility methods and should not generally be used directly, unless you are targeting the `Unwrap*` traits.
*/
#[derive(
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug,
FromNoError,
EnumDesc(
FromNoError!,
EnumDesc!(
NegOverflow => "conversion resulted in negative overflow",
PosOverflow => "conversion resulted in positive overflow",
),
FromName(NegOverflow<T>),
FromName(PosOverflow<T>),
FromRemap(RangeError<T>(NegOverflow, PosOverflow))
FromName!(NegOverflow<T>),
FromName!(PosOverflow<T>),
FromRemap!(RangeError<T>(NegOverflow, PosOverflow))
)]
pub enum RangeErrorKind {
/// Input was too negative for the target type.
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ fn too_many_errors() -> Result<(), GeneralErrorKind> {
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(not(feature = "std"))] extern crate core as std;

#[macro_use] extern crate custom_derive;
#[macro_use]
extern crate macro_attr;

// Exported macros.
pub mod macros;
Expand Down
10 changes: 5 additions & 5 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ This macro attempts to derive an implementation of the [`TryFrom`](../trait.TryF

If a conversion fails (due to there being no matching variant for the specified integer value `src`), then the conversion returns `Err(Unrepresentable(src))` (see [`Unrepresentable`](../errors/struct.Unrepresentable.html)).

It is compatible with the [`custom_derive!`](https://crates.io/crates/custom_derive) macro.
It is compatible with the [`macro_attr!`](https://crates.io/crates/macro-attr) macro.

## Example

Using `custom_derive!`:
Using `macro_attr!`:

```
#[macro_use] extern crate conv;
#[macro_use] extern crate custom_derive;
#[macro_use] extern crate macro_attr;

custom_derive! {
#[derive(Debug, PartialEq, TryFrom(i32))]
macro_attr! {
#[derive(Debug, PartialEq, TryFrom!(i32))]
enum Colours {
Red = 0,
Green = 5,
Expand Down