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

Swap macro re-export modules (#405) #406

Merged
merged 12 commits into from
Sep 9, 2024
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.0.1 - Unreleased

## 2.0.0 - Unreleased

### Breaking changes

- `use derive_more::SomeTrait` now imports macro only. Importing macro with
its trait along is possible now via `use derive_more::with_trait::SomeTrait`.
([#406](https://github.com/JelteF/derive_more/pull/406))

### Fixed

Expand All @@ -14,7 +21,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
([#399](https://github.com/JelteF/derive_more/pull/399))
- `unreachable_code` warnings on generated code when `!` (never type) is used.
([#404](https://github.com/JelteF/derive_more/pull/404))
- Fix ambiguous associated item error when deriving `TryFrom`, `TryInto` or `FromStr` with an associated item called `Error` or `Err` respectively.
- Ambiguous associated item error when deriving `TryFrom`, `TryInto` or `FromStr`
with an associated item called `Error` or `Err` respectively.
([#410](https://github.com/JelteF/derive_more/pull/410))


## 1.0.0 - 2024-08-07
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,18 @@ These don't derive traits, but derive static methods instead.

### Re-exports

This crate also re-exports all the standard library traits that it adds derives
for. So, both the `Display` derive and the `Display` trait will be in scope when
you add the following code:
This crate also re-exports all the standard library traits, that it adds derives
for, in the `with_trait` module. So, both the `Display` derive and the `Display`
trait will be in scope when you add the following code:
```rust
use derive_more::Display; // also imports `core::fmt::Display`
use derive_more::with_trait::Display; // also imports `core::fmt::Display`
```

For derive macros only, without the corresponding traits, do import them from
the `derive` module:
By default, derive macros only, without the corresponding traits, are imported from
the crate's root (or from the `derive` module):
```rust
use derive_more::derive::Display; // imports macro only
use derive_more::Display; // imports macro only
use derive_more::derive::*; // imports all macros only
```

#### Hygiene
Expand Down
6 changes: 3 additions & 3 deletions impl/doc/add.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Code like this will be generated:

```rust
# struct MyInts(i32, i32);
impl derive_more::Add for MyInts {
impl derive_more::core::ops::Add for MyInts {
type Output = MyInts;
fn add(self, rhs: MyInts) -> MyInts {
MyInts(self.0.add(rhs.0), self.1.add(rhs.1))
Expand Down Expand Up @@ -60,7 +60,7 @@ Code like this will be generated:
# x: i32,
# y: i32,
# }
impl derive_more::Add for Point2D {
impl derive_more::core::ops::Add for Point2D {
type Output = Point2D;
fn add(self, rhs: Point2D) -> Point2D {
Point2D {
Expand Down Expand Up @@ -112,7 +112,7 @@ Code like this will be generated:
# UnsignedTwo(u32),
# Unit,
# }
impl derive_more::Add for MixedInts {
impl derive_more::core::ops::Add for MixedInts {
type Output = Result<MixedInts, derive_more::BinaryError>;
fn add(self, rhs: MixedInts) -> Result<MixedInts, derive_more::BinaryError> {
match (self, rhs) {
Expand Down
4 changes: 2 additions & 2 deletions impl/doc/add_assign.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Code like this will be generated:

```rust
# struct MyInts(i32, i32);
impl derive_more::AddAssign for MyInts {
impl derive_more::core::ops::AddAssign for MyInts {
fn add_assign(&mut self, rhs: MyInts) {
self.0.add_assign(rhs.0);
self.1.add_assign(rhs.1);
Expand Down Expand Up @@ -56,7 +56,7 @@ Code like this will be generated:
# x: i32,
# y: i32,
# }
impl derive_more::AddAssign for Point2D {
impl derive_more::core::ops::AddAssign for Point2D {
fn add_assign(&mut self, rhs: Point2D) {
self.x.add_assign(rhs.x);
self.y.add_assign(rhs.y);
Expand Down
6 changes: 3 additions & 3 deletions impl/doc/as_mut.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Generates:

```rust
# struct MyWrapper(String);
impl derive_more::AsMut<String> for MyWrapper {
impl AsMut<String> for MyWrapper {
fn as_mut(&mut self) -> &mut String {
&mut self.0
}
Expand All @@ -50,9 +50,9 @@ This generates code equivalent to:

```rust
# struct SingleFieldForward(Vec<i32>);
impl<T: ?Sized> derive_more::AsMut<T> for SingleFieldForward
impl<T: ?Sized> AsMut<T> for SingleFieldForward
where
Vec<i32>: derive_more::AsMut<T>,
Vec<i32>: AsMut<T>,
{
#[inline]
fn as_mut(&mut self) -> &mut T {
Expand Down
6 changes: 3 additions & 3 deletions impl/doc/as_ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Generates:

```rust
# struct MyWrapper(String);
impl derive_more::AsRef<String> for MyWrapper {
impl AsRef<String> for MyWrapper {
fn as_ref(&self) -> &String {
&self.0
}
Expand All @@ -50,9 +50,9 @@ This generates code equivalent to:

```rust
# struct SingleFieldForward(Vec<i32>);
impl<T: ?Sized> derive_more::AsRef<T> for SingleFieldForward
impl<T: ?Sized> AsRef<T> for SingleFieldForward
where
Vec<i32>: derive_more::AsRef<T>,
Vec<i32>: AsRef<T>,
{
#[inline]
fn as_ref(&self) -> &T {
Expand Down
8 changes: 4 additions & 4 deletions impl/doc/deref.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Code like this will be generated:
# cool: bool,
# vec: Vec<i32>,
# }
impl derive_more::Deref for CoolVec {
impl derive_more::core::ops::Deref for CoolVec {
type Target = Vec<i32>;
#[inline]
fn deref(&self) -> &Self::Target {
Expand All @@ -90,11 +90,11 @@ Code like this will be generated:

```rust
# struct MyBoxedInt(Box<i32>);
impl derive_more::Deref for MyBoxedInt {
type Target = <Box<i32> as derive_more::Deref>::Target;
impl derive_more::core::ops::Deref for MyBoxedInt {
type Target = <Box<i32> as derive_more::core::ops::Deref>::Target;
#[inline]
fn deref(&self) -> &Self::Target {
<Box<i32> as derive_more::Deref>::deref(&self.0)
<Box<i32> as derive_more::core::ops::Deref>::deref(&self.0)
}
}
```
Expand Down
6 changes: 3 additions & 3 deletions impl/doc/deref_mut.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Code like this will be generated:
# &self.vec
# }
# }
impl derive_more::DerefMut for CoolVec {
impl derive_more::core::ops::DerefMut for CoolVec {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.vec
Expand Down Expand Up @@ -116,10 +116,10 @@ When deriving a forwarded `DerefMut` for a struct:
# <Box<i32> as Deref>::deref(&self.0)
# }
# }
impl derive_more::DerefMut for MyBoxedInt {
impl derive_more::core::ops::DerefMut for MyBoxedInt {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
<Box<i32> as derive_more::DerefMut>::deref_mut(&mut self.0)
<Box<i32> as derive_more::core::ops::DerefMut>::deref_mut(&mut self.0)
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions impl/doc/display.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ once to get the address of the field itself, instead of the address of the
reference to the field:

```rust
# use derive_more::Display;
# use derive_more::with_trait::Display;
#
#[derive(Display)]
#[display("{field:p} {:p}", *field)]
Expand Down Expand Up @@ -107,7 +107,7 @@ Explicitly specified bounds are added to the inferred ones. Note how no `V: Disp
because it's inferred already.

```rust
# use derive_more::Display;
# use derive_more::with_trait::Display;
#
# trait MyTrait { fn my_function(&self) -> i32; }
#
Expand Down
14 changes: 7 additions & 7 deletions impl/doc/from_str.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Code like this will be generated:

```rust
# struct MyInt(i32);
impl derive_more::FromStr for MyInt {
type Err = <i32 as derive_more::FromStr>::Err;
fn from_str(src: &str) -> Result<Self, <i32 as derive_more::FromStr>::Err> {
impl derive_more::core::str::FromStr for MyInt {
type Err = <i32 as derive_more::core::str::FromStr>::Err;
fn from_str(src: &str) -> Result<Self, <i32 as derive_more::core::str::FromStr>::Err> {
return Ok(MyInt(i32::from_str(src)?));
}
}
Expand Down Expand Up @@ -74,9 +74,9 @@ Code like this will be generated:
# struct Point1D {
# x: i32,
# }
impl derive_more::FromStr for Point1D {
type Err = <i32 as derive_more::FromStr>::Err;
fn from_str(src: &str) -> Result<Self, <i32 as derive_more::FromStr>::Err> {
impl derive_more::core::str::FromStr for Point1D {
type Err = <i32 as derive_more::core::str::FromStr>::Err;
fn from_str(src: &str) -> Result<Self, <i32 as derive_more::core::str::FromStr>::Err> {
return Ok(Point1D {
x: i32::from_str(src)?,
});
Expand Down Expand Up @@ -121,7 +121,7 @@ Code like this will be generated:
# Baz,
# }
#
impl derive_more::FromStr for EnumNoFields {
impl derive_more::core::str::FromStr for EnumNoFields {
type Err = derive_more::FromStrError;
fn from_str(src: &str) -> Result<Self, derive_more::FromStrError> {
Ok(match src.to_lowercase().as_str() {
Expand Down
8 changes: 4 additions & 4 deletions impl/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ Code like this will be generated:
# numbers: Vec<i32>,
# useless: bool,
# }
impl<__IdxT> derive_more::Index<__IdxT> for Numbers
impl<__IdxT> derive_more::core::ops::Index<__IdxT> for Numbers
where
Vec<i32>: derive_more::Index<__IdxT>,
Vec<i32>: derive_more::core::ops::Index<__IdxT>,
{
type Output = <Vec<i32> as derive_more::Index<__IdxT>>::Output;
type Output = <Vec<i32> as derive_more::core::ops::Index<__IdxT>>::Output;
#[inline]
fn index(&self, idx: __IdxT) -> &Self::Output {
<Vec<i32> as derive_more::Index<__IdxT>>::index(&self.numbers, idx)
<Vec<i32> as derive_more::core::ops::Index<__IdxT>>::index(&self.numbers, idx)
}
}
```
Expand Down
6 changes: 3 additions & 3 deletions impl/doc/index_mut.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ Code like this will be generated to implement `IndexMut`:
# <Vec<i32> as Index<__IdxT>>::index(&self.numbers, idx)
# }
# }
impl<__IdxT> derive_more::IndexMut<__IdxT> for Numbers
impl<__IdxT> derive_more::core::ops::IndexMut<__IdxT> for Numbers
where
Vec<i32>: derive_more::IndexMut<__IdxT>,
Vec<i32>: derive_more::core::ops::IndexMut<__IdxT>,
{
#[inline]
fn index_mut(&mut self, idx: __IdxT) -> &mut Self::Output {
<Vec<i32> as derive_more::IndexMut<__IdxT>>::index_mut(&mut self.numbers, idx)
<Vec<i32> as derive_more::core::ops::IndexMut<__IdxT>>::index_mut(&mut self.numbers, idx)
}
}
```
Expand Down
26 changes: 13 additions & 13 deletions impl/doc/into_iterator.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct Numbers {

assert_eq!(Some(5), MyVec(vec![5, 8]).into_iter().next());

let mut nums = Numbers{numbers: vec![100, 200], useless: false};
let mut nums = Numbers { numbers: vec![100, 200], useless: false };
assert_eq!(Some(&100), (&nums).into_iter().next());
assert_eq!(Some(&mut 100), (&mut nums).into_iter().next());
assert_eq!(Some(100), nums.into_iter().next());
Expand Down Expand Up @@ -63,30 +63,30 @@ Code like this will be generated:
# numbers: Vec<i32>,
# useless: bool,
# }
impl derive_more::IntoIterator for Numbers {
type Item = <Vec<i32> as derive_more::IntoIterator>::Item;
type IntoIter = <Vec<i32> as derive_more::IntoIterator>::IntoIter;
impl IntoIterator for Numbers {
type Item = <Vec<i32> as IntoIterator>::Item;
type IntoIter = <Vec<i32> as IntoIterator>::IntoIter;
#[inline]
fn into_iter(self) -> Self::IntoIter {
<Vec<i32> as derive_more::IntoIterator>::into_iter(self.numbers)
<Vec<i32> as IntoIterator>::into_iter(self.numbers)
}
}

impl<'__deriveMoreLifetime> derive_more::IntoIterator for &'__deriveMoreLifetime Numbers {
type Item = <&'__deriveMoreLifetime Vec<i32> as derive_more::IntoIterator>::Item;
type IntoIter = <&'__deriveMoreLifetime Vec<i32> as derive_more::IntoIterator>::IntoIter;
impl<'__deriveMoreLifetime> IntoIterator for &'__deriveMoreLifetime Numbers {
type Item = <&'__deriveMoreLifetime Vec<i32> as IntoIterator>::Item;
type IntoIter = <&'__deriveMoreLifetime Vec<i32> as IntoIterator>::IntoIter;
#[inline]
fn into_iter(self) -> Self::IntoIter {
<&'__deriveMoreLifetime Vec<i32> as derive_more::IntoIterator>::into_iter(&self.numbers)
<&'__deriveMoreLifetime Vec<i32> as IntoIterator>::into_iter(&self.numbers)
}
}

impl<'__deriveMoreLifetime> derive_more::IntoIterator for &'__deriveMoreLifetime mut Numbers {
type Item = <&'__deriveMoreLifetime mut Vec<i32> as derive_more::IntoIterator>::Item;
type IntoIter = <&'__deriveMoreLifetime mut Vec<i32> as derive_more::IntoIterator>::IntoIter;
impl<'__deriveMoreLifetime> IntoIterator for &'__deriveMoreLifetime mut Numbers {
type Item = <&'__deriveMoreLifetime mut Vec<i32> as IntoIterator>::Item;
type IntoIter = <&'__deriveMoreLifetime mut Vec<i32> as IntoIterator>::IntoIter;
#[inline]
fn into_iter(self) -> Self::IntoIter {
<&'__deriveMoreLifetime mut Vec<i32> as derive_more::IntoIterator>::into_iter(
<&'__deriveMoreLifetime mut Vec<i32> as IntoIterator>::into_iter(
&mut self.numbers,
)
}
Expand Down
16 changes: 8 additions & 8 deletions impl/doc/mul.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Code like this will be generated:

```rust
# struct MyInt(i32);
impl<__RhsT> derive_more::Mul<__RhsT> for MyInt
where i32: derive_more::Mul<__RhsT, Output = i32>
impl<__RhsT> derive_more::core::ops::Mul<__RhsT> for MyInt
where i32: derive_more::core::ops::Mul<__RhsT, Output = i32>
{
type Output = MyInt;
fn mul(self, rhs: __RhsT) -> MyInt {
Expand All @@ -60,8 +60,8 @@ Code like this will be generated:

```rust
# struct MyInts(i32, i32);
impl<__RhsT: Copy> derive_more::Mul<__RhsT> for MyInts
where i32: derive_more::Mul<__RhsT, Output = i32>
impl<__RhsT: Copy> derive_more::core::ops::Mul<__RhsT> for MyInts
where i32: derive_more::core::ops::Mul<__RhsT, Output = i32>
{
type Output = MyInts;
fn mul(self, rhs: __RhsT) -> MyInts {
Expand Down Expand Up @@ -94,8 +94,8 @@ Code like this will be generated:
# struct Point1D {
# x: i32,
# }
impl<__RhsT> derive_more::Mul<__RhsT> for Point1D
where i32: derive_more::Mul<__RhsT, Output = i32>
impl<__RhsT> derive_more::core::ops::Mul<__RhsT> for Point1D
where i32: derive_more::core::ops::Mul<__RhsT, Output = i32>
{
type Output = Point1D;
fn mul(self, rhs: __RhsT) -> Point1D {
Expand Down Expand Up @@ -125,8 +125,8 @@ Code like this will be generated:
# x: i32,
# y: i32,
# }
impl<__RhsT: Copy> derive_more::Mul<__RhsT> for Point2D
where i32: derive_more::Mul<__RhsT, Output = i32>
impl<__RhsT: Copy> derive_more::core::ops::Mul<__RhsT> for Point2D
where i32: derive_more::core::ops::Mul<__RhsT, Output = i32>
{
type Output = Point2D;
fn mul(self, rhs: __RhsT) -> Point2D {
Expand Down
8 changes: 4 additions & 4 deletions impl/doc/mul_assign.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Code like this will be generated:

```rust
# struct MyInts(i32, i32);
impl<__RhsT: Copy> derive_more::MulAssign<__RhsT> for MyInts
where i32: derive_more::MulAssign<__RhsT>
impl<__RhsT: Copy> derive_more::core::ops::MulAssign<__RhsT> for MyInts
where i32: derive_more::core::ops::MulAssign<__RhsT>
{
fn mul_assign(&mut self, rhs: __RhsT) {
self.0.mul_assign(rhs);
Expand Down Expand Up @@ -64,8 +64,8 @@ Code like this will be generated:
# x: i32,
# y: i32,
# }
impl<__RhsT: Copy> derive_more::MulAssign<__RhsT> for Point2D
where i32: derive_more::MulAssign<__RhsT>
impl<__RhsT: Copy> derive_more::core::ops::MulAssign<__RhsT> for Point2D
where i32: derive_more::core::ops::MulAssign<__RhsT>
{
fn mul_assign(&mut self, rhs: __RhsT) {
self.x.mul_assign(rhs);
Expand Down
Loading