Skip to content

Commit

Permalink
doc: document derive_use_cargo feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Dec 13, 2023
1 parent af636c1 commit ce4a5cf
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 37 deletions.
96 changes: 60 additions & 36 deletions borsh-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,28 @@ Attribute takes literal string value, which is the syn's [Path] to `borsh` crate
Attribute is optional.
1. If the attribute is not provided, [crate_name](proc_macro_crate::crate_name) is used to find a version of `borsh`
in `[dependencies]` of the relevant `Cargo.toml`. If there is no match, a compilation error, similar to the following, is raised:
1. If the attribute is not provided:
```bash
1 error: proc-macro derive panicked
--> path/to/file.rs:27:10
|
27 | #[derive(BorshSerialize, BorshDeserialize)]
| ^^^^^^^^^^^^^^
|
= help: message: called `Result::unwrap()` on an `Err` value: CrateNotFound { crate_name: "borsh", path: "/path/to/Cargo.toml" }
```
- If `proc-macro-crate` feature of `borsh-derive`, which is controlled by `derive_use_cargo` feature
of `borsh`, is enabled, then
[crate_name](proc_macro_crate::crate_name) is used to find a version of `borsh`
in `[dependencies]` of the relevant `Cargo.toml`. If there is no match, a compilation error, similar to the following, is raised:
```bash
1 error: proc-macro derive panicked
--> path/to/file.rs:27:10
|
27 | #[derive(BorshSerialize, BorshDeserialize)]
| ^^^^^^^^^^^^^^
|
= help: message: called `Result::unwrap()` on an `Err` value: CrateNotFound { crate_name: "borsh", path: "/path/to/Cargo.toml" }
```
- If `proc-macro-crate` feature of `borsh-derive` is disabled, the path to `borsh` is assumed to be simply `borsh`.
The feature can be opted out of to remove dependency on `cargo` in build process.
2. If the attribute is provided, the check for `borsh` in `[dependencies]` of the relevant `Cargo.toml` is skipped.
2. If the attribute is provided, the check for `borsh` in `[dependencies]` of the relevant `Cargo.toml` is skipped
and the provided attribute value is used instead.
Examples of usage:
Expand Down Expand Up @@ -360,20 +368,28 @@ Attribute takes literal string value, which is the syn's [Path] to `borsh` crate
Attribute is optional.
1. If the attribute is not provided, [crate_name](proc_macro_crate::crate_name) is used to find a version of `borsh`
in `[dependencies]` of the relevant `Cargo.toml`. If there is no match, a compilation error, similar to the following, is raised:
1. If the attribute is not provided:
```bash
1 error: proc-macro derive panicked
--> path/to/file.rs:27:10
|
27 | #[derive(BorshDeserialize, BorshSerialize)]
| ^^^^^^^^^^^^^^^^
|
= help: message: called `Result::unwrap()` on an `Err` value: CrateNotFound { crate_name: "borsh", path: "/path/to/Cargo.toml" }
```
- If `proc-macro-crate` feature of `borsh-derive`, which is controlled by `derive_use_cargo` feature
of `borsh`, is enabled, then
[crate_name](proc_macro_crate::crate_name) is used to find a version of `borsh`
in `[dependencies]` of the relevant `Cargo.toml`. If there is no match, a compilation error, similar to the following, is raised:
```bash
1 error: proc-macro derive panicked
--> path/to/file.rs:27:10
|
27 | #[derive(BorshDeserialize, BorshSerialize)]
| ^^^^^^^^^^^^^^^^
|
= help: message: called `Result::unwrap()` on an `Err` value: CrateNotFound { crate_name: "borsh", path: "/path/to/Cargo.toml" }
```
2. If the attribute is provided, the check for `borsh` in `[dependencies]` of the relevant `Cargo.toml` is skipped.
- If `proc-macro-crate` feature of `borsh-derive` is disabled, the path to `borsh` is assumed to be simply `borsh`.
The feature can be opted out of to remove dependency on `cargo` in build process.
2. If the attribute is provided, the check for `borsh` in `[dependencies]` of the relevant `Cargo.toml` is skipped
and the provided attribute value is used instead.
Examples of usage:
Expand Down Expand Up @@ -696,20 +712,28 @@ Attribute takes literal string value, which is the syn's [Path] to `borsh` crate
Attribute is optional.
1. If the attribute is not provided, [crate_name](proc_macro_crate::crate_name) is used to find a version of `borsh`
in `[dependencies]` of the relevant `Cargo.toml`. If there is no match, a compilation error, similar to the following, is raised:
1. If the attribute is not provided:
```bash
1 error: proc-macro derive panicked
--> path/to/file.rs:27:10
|
27 | #[derive(BorshSchema, BorshSerialize)]
| ^^^^^^^^^^^
|
= help: message: called `Result::unwrap()` on an `Err` value: CrateNotFound { crate_name: "borsh", path: "/path/to/Cargo.toml" }
```
- If `proc-macro-crate` feature of `borsh-derive`, which is controlled by `derive_use_cargo` feature
of `borsh`, is enabled, then
[crate_name](proc_macro_crate::crate_name) is used to find a version of `borsh`
in `[dependencies]` of the relevant `Cargo.toml`. If there is no match, a compilation error, similar to the following, is raised:
```bash
1 error: proc-macro derive panicked
--> path/to/file.rs:27:10
|
27 | #[derive(BorshSchema, BorshSerialize)]
| ^^^^^^^^^^^
|
= help: message: called `Result::unwrap()` on an `Err` value: CrateNotFound { crate_name: "borsh", path: "/path/to/Cargo.toml" }
```
- If `proc-macro-crate` feature of `borsh-derive` is disabled, the path to `borsh` is assumed to be simply `borsh`.
The feature can be opted out of to remove dependency on `cargo` in build process.
2. If the attribute is provided, the check for `borsh` in `[dependencies]` of the relevant `Cargo.toml` is skipped.
2. If the attribute is provided, the check for `borsh` in `[dependencies]` of the relevant `Cargo.toml` is skipped
and the provided attribute value is used instead.
Examples of usage:
Expand Down
8 changes: 7 additions & 1 deletion borsh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@
### Default features
* **std** - enabled by default.
* **std** , **derive_use_cargo** - enabled by default.
### Other features
* **derive** -
Gates derive macros of [BorshSerialize] and
[BorshDeserialize] traits.
* **derive_use_cargo** -
Enables `proc-macro-crate` feature of `borsh-derive` dependency, which tracks `borsh`
crate rename in `Cargo.toml` via `cargo`.
This feature has effect only if **derive** feature is enabled.
More details are mentioned in `#[borsh(crate = ...)]` attribute description in [borsh_derive] doc.
* **unstable__schema** -
Gates [BorshSchema] trait and its derive macro.
Gates [schema] module.
Expand Down

0 comments on commit ce4a5cf

Please sign in to comment.