Skip to content

Commit 7e60fe1

Browse files
author
Tyler Slabinski
committed
Attempt to resolve doc testing errors
1 parent a7db7c3 commit 7e60fe1

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

doc/borrow_mut.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@ corresponding to one of the fields of the decorated type.
55
This allows types which contain some `T` to be passed anywhere that an
66
`BorrowMut<T>` is accepted.
77

8+
Note that `BorrowMut<T>` expects the type to also implement `Borrow<T>`.
9+
810
# Newtypes and Structs with One Field
911

1012
When `BorrowMut` is derived for a newtype or struct with one field, a single
1113
implementation is generated to expose the underlying field.
1214

1315
```rust
16+
# use core::borrow::Borrow;
1417
# use core::borrow::BorrowMut;
1518
# #[macro_use] extern crate derive_more;
1619
# fn main(){}
17-
#[derive(BorrowMut)]
20+
#[derive(Borrow, BorrowMut)]
1821
struct MyWrapper(String);
1922
```
2023

2124
Generates:
2225

2326
```rust
27+
# use core::borrow::Borrow;
2428
# use core::borrow::BorrowMut;
29+
# #[derive(Borrow)]
2530
# struct MyWrapper(String);
2631
impl BorrowMut<String> for MyWrapper {
2732
fn borrow_mut(&mut self) -> &mut String {
@@ -37,7 +42,8 @@ implements all `BorrowMut` for all types that `Vec<i32>` implements `BorrowMut`
3742
```rust
3843
# use core::borrow::BorrowMut;
3944
# #[macro_use] extern crate derive_more;
40-
#[derive(BorrowMut)]
45+
#[derive(Borrow, BorrowMut)]
46+
#[borrow(forward)]
4147
#[borrow_mut(forward)]
4248
struct SingleFieldForward(Vec<i32>);
4349

@@ -51,6 +57,7 @@ fn main() {
5157
This generates:
5258

5359
```rust
60+
# #[derive(Borrow)]
5461
# struct SingleFieldForward(Vec<i32>);
5562
impl<__BorrowMutT: ?::core::marker::Sized> ::core::borrow::BorrowMut<__BorrowMutT> for SingleFieldForward
5663
where
@@ -72,13 +79,16 @@ An implementation will be generated for each indicated field.
7279
You can also exclude a specific field by using `#[borrow_mut(ignore)]`.
7380

7481
```rust
82+
# use core::borrow::Borrow;
7583
# use core::borrow::BorrowMut;
7684
# #[macro_use] extern crate derive_more;
7785
# fn main(){}
78-
#[derive(BorrowMut)]
86+
#[derive(Borrow, BorrowMut)]
7987
struct MyWrapper {
88+
#[borrow]
8089
#[borrow_mut]
8190
name: String,
91+
#[borrow]
8292
#[borrow_mut]
8393
num: i32,
8494
valid: bool,
@@ -90,7 +100,9 @@ struct MyWrapper {
90100
Generates:
91101

92102
```
103+
# use core::borrow::Borrow;
93104
# use core::borrow::BorrowMut;
105+
# #[derive(Borrow)]
94106
# struct MyWrapper {
95107
# name: String,
96108
# num: i32,
@@ -113,6 +125,7 @@ Note that `BorrowMut<T>` may only be implemented once for any given type `T`. Th
113125
mark more than one field of the same type with `#[borrow_mut]` will result in a compilation error.
114126

115127
```compile_fail
128+
# use core::borrow::Borrow;
116129
# use core::borrow::BorrowMut;
117130
# #[macro_use] extern crate derive_more;
118131
# fn main(){}

0 commit comments

Comments
 (0)