Skip to content

Commit

Permalink
Resolve doc checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Slabinski committed Nov 3, 2020
1 parent c21ddd6 commit a7db7c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 9 additions & 3 deletions doc/borrow.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ When `Borrow` is derived for a newtype or struct with one field, a single
implementation is generated to expose the underlying field.

```rust
# use core::borrow::Borrow;
# #[macro_use] extern crate derive_more;
# fn main(){}
#[derive(Borrow)]
Expand All @@ -20,6 +21,7 @@ struct MyWrapper(String);
Generates:

```rust
# use core::borrow::Borrow;
# struct MyWrapper(String);
impl Borrow<String> for MyWrapper {
fn borrow(&self) -> &String {
Expand All @@ -33,6 +35,7 @@ to the `borrow` implementation of the field. So here `SigleFieldForward`
implements all `Borrow` for all types that `Vec<i32>` implements `Borrow` for.

```rust
# use core::borrow::Borrow;
# #[macro_use] extern crate derive_more;
#[derive(Borrow)]
#[borrow(forward)]
Expand All @@ -49,13 +52,13 @@ This generates:

```rust
# struct SingleFieldForward(Vec<i32>);
impl<__BorrowT: ?::core::marker::Sized> ::core::convert::Borrow<__BorrowT> for SingleFieldForward
impl<__BorrowT: ?::core::marker::Sized> ::core::borrow::Borrow<__BorrowT> for SingleFieldForward
where
Vec<i32>: ::core::convert::Borrow<__BorrowT>,
Vec<i32>: ::core::borrow::Borrow<__BorrowT>,
{
#[inline]
fn borrow(&self) -> &__BorrowT {
<Vec<i32> as ::core::convert::Borrow<__BorrowT>>::borrow(&self.0)
<Vec<i32> as ::core::borrow::Borrow<__BorrowT>>::borrow(&self.0)
}
}
```
Expand All @@ -68,6 +71,7 @@ An implementation will be generated for each indicated field.
You can also exclude a specific field by using `#[borrow(ignore)]`.

```rust
# use core::borrow::Borrow;
# #[macro_use] extern crate derive_more;
# fn main(){}
#[derive(Borrow)]
Expand All @@ -84,6 +88,7 @@ struct MyWrapper {
Generates:

```rust
# use core::borrow::Borrow;
# struct MyWrapper {
# name: String,
# num: i32,
Expand All @@ -107,6 +112,7 @@ This means any attempt to mark more than one field of the same type with
`#[borrow]` will result in a compilation error.

```compile_fail
# use core::borrow::Borrow;
# #[macro_use] extern crate derive_more;
# fn main(){}
// Error! Conflicting implementations of Borrow<String>
Expand Down
12 changes: 9 additions & 3 deletions doc/borrow_mut.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ When `BorrowMut` is derived for a newtype or struct with one field, a single
implementation is generated to expose the underlying field.

```rust
# use core::borrow::BorrowMut;
# #[macro_use] extern crate derive_more;
# fn main(){}
#[derive(BorrowMut)]
Expand All @@ -20,6 +21,7 @@ struct MyWrapper(String);
Generates:

```rust
# use core::borrow::BorrowMut;
# struct MyWrapper(String);
impl BorrowMut<String> for MyWrapper {
fn borrow_mut(&mut self) -> &mut String {
Expand All @@ -33,6 +35,7 @@ to the `borrow_mut` implementation of the field. So here `SigleFieldForward`
implements all `BorrowMut` for all types that `Vec<i32>` implements `BorrowMut` for.

```rust
# use core::borrow::BorrowMut;
# #[macro_use] extern crate derive_more;
#[derive(BorrowMut)]
#[borrow_mut(forward)]
Expand All @@ -49,13 +52,13 @@ This generates:

```rust
# struct SingleFieldForward(Vec<i32>);
impl<__BorrowMutT: ?::core::marker::Sized> ::core::convert::BorrowMut<__BorrowMutT> for SingleFieldForward
impl<__BorrowMutT: ?::core::marker::Sized> ::core::borrow::BorrowMut<__BorrowMutT> for SingleFieldForward
where
Vec<i32>: ::core::convert::BorrowMut<__BorrowMutT>,
Vec<i32>: ::core::borrow::BorrowMut<__BorrowMutT>,
{
#[inline]
fn borrow_mut(&mut self) -> &mut __BorrowMutT {
<Vec<i32> as ::core::convert::BorrowMut<__BorrowMutT>>::borrow_mut(&mut self.0)
<Vec<i32> as ::core::borrow::BorrowMut<__BorrowMutT>>::borrow_mut(&mut self.0)
}
}
```
Expand All @@ -69,6 +72,7 @@ An implementation will be generated for each indicated field.
You can also exclude a specific field by using `#[borrow_mut(ignore)]`.

```rust
# use core::borrow::BorrowMut;
# #[macro_use] extern crate derive_more;
# fn main(){}
#[derive(BorrowMut)]
Expand All @@ -86,6 +90,7 @@ struct MyWrapper {
Generates:

```
# use core::borrow::BorrowMut;
# struct MyWrapper {
# name: String,
# num: i32,
Expand All @@ -108,6 +113,7 @@ Note that `BorrowMut<T>` may only be implemented once for any given type `T`. Th
mark more than one field of the same type with `#[borrow_mut]` will result in a compilation error.

```compile_fail
# use core::borrow::BorrowMut;
# #[macro_use] extern crate derive_more;
# fn main(){}
// Error! Conflicting implementations of BorrowMut<String>
Expand Down

0 comments on commit a7db7c3

Please sign in to comment.