Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
This commit is contained in:
1
vendor/log/.cargo-checksum.json
vendored
Normal file
1
vendor/log/.cargo-checksum.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"files":{"CHANGELOG.md":"4cf5d5c08ecf2cca9bfc6c0393fb06375675e1a712cd0da17426d54dd6b26281","Cargo.toml":"400053190237140d908218465ab8942fe65196c43925be6faef37e284b5817ff","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"788bda1deb337541be7ddaf8a7483d1c315f008aeab72374973135ad490e06c4","benches/value.rs":"6ce7689c8c714c93fa58afa984aefe54f0fc279fdd69e1582d013c97d1688eba","src/__private_api.rs":"de6799f0772181878a2fbfb93146641243a86f1115f2e8234a255d70105e2e65","src/kv/error.rs":"5dea46a9eb2128442a60f7f8a0e0b9e5f155bc0e9ecc5134f91e466cb04c8a31","src/kv/key.rs":"941979c92db5f9b999b9eba4f96a8d43da034da80849fbfa65277f122b5fc39f","src/kv/mod.rs":"3592b750c206d5a36545d0c5f2e5db79c499c3f96dced13c5aeeacc7409b4ff6","src/kv/source.rs":"4fd7f0083caef44094984c02bd3d15d7e5fd6b95e809b2d6abab31aa8d01f5c3","src/kv/value.rs":"7f0ee0327dcfbb3df3ed4f0c8caed4bebd4b76bb7407f32f100d660f2a10eabd","src/lib.rs":"1332fb825d498244bf068ce929d744c7316888c7f99e4711149af69ed028730c","src/macros.rs":"f0604416b1a839ba84509c17bff3741766cfa401cb09c0b00e33c36ae1c710ad","src/serde.rs":"1f8614b42ffb1b34bdf58ce3ab6584b760a8a9e9aa6e00b27dc229cbc46f0a2b","triagebot.toml":"a135e10c777cd13459559bdf74fb704c1379af7c9b0f70bc49fa6f5a837daa81"},"package":"b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"}
|
273
vendor/log/CHANGELOG.md
vendored
Normal file
273
vendor/log/CHANGELOG.md
vendored
Normal file
@ -0,0 +1,273 @@
|
||||
# Change Log
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.4.20] - 2023-07-11
|
||||
|
||||
* Remove rustversion dev-dependency by @Thomasdezeeuw in https://github.com/rust-lang/log/pull/568
|
||||
* Remove `local_inner_macros` usage by @EFanZh in https://github.com/rust-lang/log/pull/570
|
||||
|
||||
## [0.4.19] - 2023-06-10
|
||||
|
||||
* Use target_has_atomic instead of the old atomic_cas cfg by @GuillaumeGomez in https://github.com/rust-lang/log/pull/555
|
||||
* Put MSRV into Cargo.toml by @est31 in https://github.com/rust-lang/log/pull/557
|
||||
|
||||
## [0.4.18] - 2023-05-28
|
||||
|
||||
* fix markdown links (again) by @hellow554 in https://github.com/rust-lang/log/pull/513
|
||||
* add cargo doc to workflow by @hellow554 in https://github.com/rust-lang/log/pull/515
|
||||
* Apply Clippy lints by @hellow554 in https://github.com/rust-lang/log/pull/516
|
||||
* Replace ad-hoc eq_ignore_ascii_case with slice::eq_ignore_ascii_case by @glandium in https://github.com/rust-lang/log/pull/519
|
||||
* fix up windows targets by @KodrAus in https://github.com/rust-lang/log/pull/528
|
||||
* typo fix by @jiangying000 in https://github.com/rust-lang/log/pull/529
|
||||
* Remove dependency on cfg_if by @EriKWDev in https://github.com/rust-lang/log/pull/536
|
||||
* GitHub Workflows security hardening by @sashashura in https://github.com/rust-lang/log/pull/538
|
||||
* Fix build status badge by @atouchet in https://github.com/rust-lang/log/pull/539
|
||||
* Add call_logger to the documentation by @a1ecbr0wn in https://github.com/rust-lang/log/pull/547
|
||||
* Use stable internals for key-value API by @KodrAus in https://github.com/rust-lang/log/pull/550
|
||||
* Change wording of list of implementations by @Thomasdezeeuw in https://github.com/rust-lang/log/pull/553
|
||||
* Add std-logger to list of implementations by @Thomasdezeeuw in https://github.com/rust-lang/log/pull/554
|
||||
* Add `set_max_level_racy` and gate `set_max_level` by @djkoloski in https://github.com/rust-lang/log/pull/544
|
||||
* [doc] src/lib.rs : prefix an unused variable with an underscore by @OccupyMars2025 in https://github.com/rust-lang/log/pull/561
|
||||
* [doc] src/macros.rs : correct grammar errors of an example in lib documentation by @OccupyMars2025 in https://github.com/rust-lang/log/pull/562
|
||||
|
||||
## [0.4.17] - 2022-04-29
|
||||
|
||||
* Update `kv_unstable` internal dependencies.
|
||||
|
||||
## [0.4.16] - 2022-03-22
|
||||
|
||||
* Fix a conflict with unqualified `Option` use in macros.
|
||||
|
||||
## [0.4.15] - 2022-02-23
|
||||
|
||||
* Silence a warning about the deprecated `spin_loop_hint`.
|
||||
* Relax ordering in the atomic `set_max_level` call.
|
||||
* Add thumbv4t-none-eabi to targets that don't support atomics
|
||||
* Allow levels to be iterated over.
|
||||
* Implement `Log` on some common wrapper types.
|
||||
* Improvements to test coverage.
|
||||
* Improvements to documentation.
|
||||
* Add key-value support to the `log!` macros.
|
||||
* Tighten `kv_unstable` internal dependencies so they don't bump past their current alpha.
|
||||
* Add a simple visit API to `kv_unstable`.
|
||||
* Support `NonZero*` integers as values in structured logging
|
||||
* Support static strings as keys in structured logging
|
||||
|
||||
## [0.4.14] - 2021-01-27
|
||||
|
||||
* Remove the `__private_api_log_lit` special case.
|
||||
* Fixed incorrect combination of `kv_unstable` and `std` features causing compile failures.
|
||||
* Remove unstable `Value::to_*` conversions that were incorrectly using `as`.
|
||||
* Rename unstable `Value::to_error` to `Value::to_borrowed_error`.
|
||||
|
||||
## [0.4.13] - 2021-01-11
|
||||
|
||||
* This is the same as `0.4.11`, except with a `kv_unstable_std` feature added to aid migrating current dependents to `0.4.14` (which was originally going to be `0.4.13` until it was decided to create a patch from `0.4.11` to minimize disruption).
|
||||
|
||||
## [0.4.12] - 2020-12-24
|
||||
|
||||
### New
|
||||
|
||||
* Support platforms without atomics by racing instead of failing to compile
|
||||
* Implement `Log` for `Box<T: Log>`
|
||||
* Update `cfg-if` to `1.0`
|
||||
* Internal reworks of the structured logging API. Removed the `Fill` API
|
||||
and added `source::as_map` and `source::as_list` to easily serialize a `Source`
|
||||
as either a map of `{key: value, ..}` or as a list of `[(key, value), ..]`.
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed deserialization of `LevelFilter` to use their `u64` index variants
|
||||
|
||||
## [0.4.11] - 2020-07-09
|
||||
|
||||
### New
|
||||
|
||||
* Support coercing structured values into concrete types.
|
||||
* Reference the `win_dbg_logger` in the readme.
|
||||
|
||||
### Fixed
|
||||
|
||||
* Updates a few deprecated items used internally.
|
||||
* Fixed issues in docs and expands sections.
|
||||
* Show the correct build badge in the readme.
|
||||
* Fix up a possible inference breakage with structured value errors.
|
||||
* Respect formatting flags in structured value formatting.
|
||||
|
||||
## [0.4.10] - 2019-12-16 (yanked)
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed the `log!` macros so they work in expression context (this regressed in `0.4.9`, which has been yanked).
|
||||
|
||||
## [0.4.9] - 2019-12-12 (yanked)
|
||||
|
||||
### Minimum Supported Rust Version
|
||||
|
||||
This release bumps the minimum compiler version to `1.31.0`. This was mainly needed for `cfg-if`,
|
||||
but between `1.16.0` and `1.31.0` there are a lot of language and library improvements we now
|
||||
take advantage of.
|
||||
|
||||
### New
|
||||
|
||||
* Unstable support for capturing key-value pairs in a record using the `log!` macros
|
||||
|
||||
### Improved
|
||||
|
||||
* Better documentation for max level filters.
|
||||
* Internal updates to line up with bumped MSRV
|
||||
|
||||
## [0.4.8] - 2019-07-28
|
||||
|
||||
### New
|
||||
|
||||
* Support attempting to get `Record` fields as static strings.
|
||||
|
||||
## [0.4.7] - 2019-07-06
|
||||
|
||||
### New
|
||||
|
||||
* Support for embedded environments with thread-unsafe initialization.
|
||||
* Initial unstable support for capturing structured data under the `kv_unstable`
|
||||
feature gate. This new API doesn't affect existing users and may change in future
|
||||
patches (so those changes may not appear in the changelog until it stabilizes).
|
||||
|
||||
### Improved
|
||||
|
||||
* Docs for using `log` with the 2018 edition.
|
||||
* Error messages for macros missing arguments.
|
||||
|
||||
## [0.4.6] - 2018-10-27
|
||||
|
||||
### Improved
|
||||
|
||||
* Support 2018-style macro import for the `log_enabled!` macro.
|
||||
|
||||
## [0.4.5] - 2018-09-03
|
||||
|
||||
### Improved
|
||||
|
||||
* Make `log`'s internal helper macros less likely to conflict with user-defined
|
||||
macros.
|
||||
|
||||
## [0.4.4] - 2018-08-17
|
||||
|
||||
### Improved
|
||||
|
||||
* Support 2018-style imports of the log macros.
|
||||
|
||||
## [0.4.3] - 2018-06-29
|
||||
|
||||
### Improved
|
||||
|
||||
* More code generation improvements.
|
||||
|
||||
## [0.4.2] - 2018-06-05
|
||||
|
||||
### Improved
|
||||
|
||||
* Log invocations now generate less code.
|
||||
|
||||
### Fixed
|
||||
|
||||
* Example Logger implementations now properly set the max log level.
|
||||
|
||||
## [0.4.1] - 2017-12-30
|
||||
|
||||
### Fixed
|
||||
|
||||
* Some doc links were fixed.
|
||||
|
||||
## [0.4.0] - 2017-12-24
|
||||
|
||||
The changes in this release include cleanup of some obscure functionality and a more robust public
|
||||
API designed to support bridges to other logging systems, and provide more flexibility to new
|
||||
features in the future.
|
||||
|
||||
### Compatibility
|
||||
|
||||
Vast portions of the Rust ecosystem use the 0.3.x release series of log, and we don't want to force
|
||||
the community to go through the pain of upgrading every crate to 0.4.x at the exact same time. Along
|
||||
with 0.4.0, we've published a new 0.3.9 release which acts as a "shim" over 0.4.0. This will allow
|
||||
crates using either version to coexist without losing messages from one side or the other.
|
||||
|
||||
There is one caveat - a log message generated by a crate using 0.4.x but consumed by a logging
|
||||
implementation using 0.3.x will not have a file name or module path. Applications affected by this
|
||||
can upgrade their logging implementations to one using 0.4.x to avoid losing this information. The
|
||||
other direction does not lose any information, fortunately!
|
||||
|
||||
**TL;DR** Libraries should feel comfortable upgrading to 0.4.0 without treating that as a breaking
|
||||
change. Applications may need to update their logging implementation (e.g. env-logger) to a newer
|
||||
version using log 0.4.x to avoid losing module and file information.
|
||||
|
||||
### New
|
||||
|
||||
* The crate is now `no_std` by default.
|
||||
* `Level` and `LevelFilter` now implement `Serialize` and `Deserialize` when the `serde` feature is
|
||||
enabled.
|
||||
* The `Record` and `Metadata` types can now be constructed by third-party code via a builder API.
|
||||
* The `logger` free function returns a reference to the logger implementation. This, along with the
|
||||
ability to construct `Record`s, makes it possible to bridge from another logging framework to
|
||||
this one without digging into the private internals of the crate. The standard `error!` `warn!`,
|
||||
etc, macros now exclusively use the public API of the crate rather than "secret" internal APIs.
|
||||
* `Log::flush` has been added to allow crates to tell the logging implementation to ensure that all
|
||||
"in flight" log events have been persisted. This can be used, for example, just before an
|
||||
application exits to ensure that asynchronous log sinks finish their work.
|
||||
|
||||
### Removed
|
||||
|
||||
* The `shutdown` and `shutdown_raw` functions have been removed. Supporting shutdown significantly
|
||||
complicated the implementation and imposed a performance cost on each logging operation.
|
||||
* The `log_panics` function and its associated `nightly` Cargo feature have been removed. Use the
|
||||
[log-panics](https://crates.io/crates/log-panics) instead.
|
||||
|
||||
### Changed
|
||||
|
||||
* The `Log` prefix has been removed from type names. For example, `LogLevelFilter` is now
|
||||
`LevelFilter`, and `LogRecord` is now `Record`.
|
||||
* The `MaxLogLevelFilter` object has been removed in favor of a `set_max_level` free function.
|
||||
* The `set_logger` free functions have been restructured. The logger is now directly passed to the
|
||||
functions rather than a closure which returns the logger. `set_logger` now takes a `&'static
|
||||
Log` and is usable in `no_std` contexts in place of the old `set_logger_raw`. `set_boxed_logger`
|
||||
is a convenience function which takes a `Box<Log>` but otherwise acts like `set_logger`. It
|
||||
requires the `std` feature.
|
||||
* The `file` and `module_path` values in `Record` no longer have the `'static` lifetime to support
|
||||
integration with other logging frameworks that don't provide a `'static` lifetime for the
|
||||
equivalent values.
|
||||
* The `file`, `line`, and `module_path` values in `Record` are now `Option`s to support integration
|
||||
with other logging frameworks that don't provide those values.
|
||||
|
||||
### In the Future
|
||||
|
||||
* We're looking to add support for *structured* logging - the inclusion of extra key-value pairs of
|
||||
information in a log event in addition to the normal string message. This should be able to be
|
||||
added in a backwards compatible manner to the 0.4.x series when the design is worked out.
|
||||
|
||||
## Older
|
||||
|
||||
Look at the [release tags] for information about older releases.
|
||||
|
||||
[Unreleased]: https://github.com/rust-lang-nursery/log/compare/0.4.18...HEAD
|
||||
[0.4.20]: https://github.com/rust-lang-nursery/log/compare/0.4.19...0.4.20
|
||||
[0.4.19]: https://github.com/rust-lang-nursery/log/compare/0.4.18...0.4.19
|
||||
[0.4.18]: https://github.com/rust-lang-nursery/log/compare/0.4.17...0.4.18
|
||||
[0.4.17]: https://github.com/rust-lang-nursery/log/compare/0.4.16...0.4.17
|
||||
[0.4.16]: https://github.com/rust-lang-nursery/log/compare/0.4.15...0.4.16
|
||||
[0.4.15]: https://github.com/rust-lang-nursery/log/compare/0.4.13...0.4.15
|
||||
[0.4.14]: https://github.com/rust-lang-nursery/log/compare/0.4.13...0.4.14
|
||||
[0.4.13]: https://github.com/rust-lang-nursery/log/compare/0.4.11...0.4.13
|
||||
[0.4.12]: https://github.com/rust-lang-nursery/log/compare/0.4.11...0.4.12
|
||||
[0.4.11]: https://github.com/rust-lang-nursery/log/compare/0.4.10...0.4.11
|
||||
[0.4.10]: https://github.com/rust-lang-nursery/log/compare/0.4.9...0.4.10
|
||||
[0.4.9]: https://github.com/rust-lang-nursery/log/compare/0.4.8...0.4.9
|
||||
[0.4.8]: https://github.com/rust-lang-nursery/log/compare/0.4.7...0.4.8
|
||||
[0.4.7]: https://github.com/rust-lang-nursery/log/compare/0.4.6...0.4.7
|
||||
[0.4.6]: https://github.com/rust-lang-nursery/log/compare/0.4.5...0.4.6
|
||||
[0.4.5]: https://github.com/rust-lang-nursery/log/compare/0.4.4...0.4.5
|
||||
[0.4.4]: https://github.com/rust-lang-nursery/log/compare/0.4.3...0.4.4
|
||||
[0.4.3]: https://github.com/rust-lang-nursery/log/compare/0.4.2...0.4.3
|
||||
[0.4.2]: https://github.com/rust-lang-nursery/log/compare/0.4.1...0.4.2
|
||||
[0.4.1]: https://github.com/rust-lang-nursery/log/compare/0.4.0...0.4.1
|
||||
[0.4.0]: https://github.com/rust-lang-nursery/log/compare/0.3.8...0.4.0
|
||||
[release tags]: https://github.com/rust-lang-nursery/log/releases
|
118
vendor/log/Cargo.toml
vendored
Normal file
118
vendor/log/Cargo.toml
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
rust-version = "1.60.0"
|
||||
name = "log"
|
||||
version = "0.4.20"
|
||||
authors = ["The Rust Project Developers"]
|
||||
exclude = ["rfcs/**/*"]
|
||||
description = """
|
||||
A lightweight logging facade for Rust
|
||||
"""
|
||||
documentation = "https://docs.rs/log"
|
||||
readme = "README.md"
|
||||
keywords = ["logging"]
|
||||
categories = ["development-tools::debugging"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/rust-lang/log"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = [
|
||||
"std",
|
||||
"serde",
|
||||
"kv_unstable_std",
|
||||
"kv_unstable_sval",
|
||||
"kv_unstable_serde",
|
||||
]
|
||||
|
||||
[[test]]
|
||||
name = "filters"
|
||||
path = "tests/filters.rs"
|
||||
harness = false
|
||||
|
||||
[[test]]
|
||||
name = "macros"
|
||||
path = "tests/macros.rs"
|
||||
harness = true
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dependencies.sval]
|
||||
version = "2.1"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dependencies.sval_ref]
|
||||
version = "2.1"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dependencies.value-bag]
|
||||
version = "1.4"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dev-dependencies.proc-macro2]
|
||||
version = "1.0.63"
|
||||
default-features = false
|
||||
|
||||
[dev-dependencies.serde]
|
||||
version = "1.0"
|
||||
features = ["derive"]
|
||||
|
||||
[dev-dependencies.serde_test]
|
||||
version = "1.0"
|
||||
|
||||
[dev-dependencies.sval]
|
||||
version = "2.1"
|
||||
|
||||
[dev-dependencies.sval_derive]
|
||||
version = "2.1"
|
||||
|
||||
[dev-dependencies.value-bag]
|
||||
version = "1.4"
|
||||
features = ["test"]
|
||||
|
||||
[features]
|
||||
kv_unstable = ["value-bag"]
|
||||
kv_unstable_serde = [
|
||||
"kv_unstable_std",
|
||||
"value-bag/serde",
|
||||
"serde",
|
||||
]
|
||||
kv_unstable_std = [
|
||||
"std",
|
||||
"kv_unstable",
|
||||
"value-bag/error",
|
||||
]
|
||||
kv_unstable_sval = [
|
||||
"kv_unstable",
|
||||
"value-bag/sval",
|
||||
"sval",
|
||||
"sval_ref",
|
||||
]
|
||||
max_level_debug = []
|
||||
max_level_error = []
|
||||
max_level_info = []
|
||||
max_level_off = []
|
||||
max_level_trace = []
|
||||
max_level_warn = []
|
||||
release_max_level_debug = []
|
||||
release_max_level_error = []
|
||||
release_max_level_info = []
|
||||
release_max_level_off = []
|
||||
release_max_level_trace = []
|
||||
release_max_level_warn = []
|
||||
std = []
|
201
vendor/log/LICENSE-APACHE
vendored
Normal file
201
vendor/log/LICENSE-APACHE
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
25
vendor/log/LICENSE-MIT
vendored
Normal file
25
vendor/log/LICENSE-MIT
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
Copyright (c) 2014 The Rust Project Developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
121
vendor/log/README.md
vendored
Normal file
121
vendor/log/README.md
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
log
|
||||
===
|
||||
|
||||
A Rust library providing a lightweight logging *facade*.
|
||||
|
||||
[](https://github.com/rust-lang/log/actions)
|
||||
[](https://crates.io/crates/log)
|
||||
[](https://docs.rs/log)
|
||||

|
||||
|
||||
* [`log` documentation](https://docs.rs/log)
|
||||
|
||||
A logging facade provides a single logging API that abstracts over the actual
|
||||
logging implementation. Libraries can use the logging API provided by this
|
||||
crate, and the consumer of those libraries can choose the logging
|
||||
implementation that is most suitable for its use case.
|
||||
|
||||
|
||||
## Minimum supported `rustc`
|
||||
|
||||
`1.60.0+`
|
||||
|
||||
This version is explicitly tested in CI and may be bumped in any release as needed. Maintaining compatibility with older compilers is a priority though, so the bar for bumping the minimum supported version is set very high. Any changes to the supported minimum version will be called out in the release notes.
|
||||
|
||||
## Usage
|
||||
|
||||
### In libraries
|
||||
|
||||
Libraries should link only to the `log` crate, and use the provided macros to
|
||||
log whatever information will be useful to downstream consumers:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
log = "0.4"
|
||||
```
|
||||
|
||||
```rust
|
||||
use log::{info, trace, warn};
|
||||
|
||||
pub fn shave_the_yak(yak: &mut Yak) {
|
||||
trace!("Commencing yak shaving");
|
||||
|
||||
loop {
|
||||
match find_a_razor() {
|
||||
Ok(razor) => {
|
||||
info!("Razor located: {}", razor);
|
||||
yak.shave(razor);
|
||||
break;
|
||||
}
|
||||
Err(err) => {
|
||||
warn!("Unable to locate a razor: {}, retrying", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### In executables
|
||||
|
||||
In order to produce log output, executables have to use a logger implementation compatible with the facade.
|
||||
There are many available implementations to choose from, here are some options:
|
||||
|
||||
* Simple minimal loggers:
|
||||
* [`env_logger`](https://docs.rs/env_logger/*/env_logger/)
|
||||
* [`simple_logger`](https://docs.rs/simple_logger/*/simple_logger/)
|
||||
* [`simplelog`](https://docs.rs/simplelog/*/simplelog/)
|
||||
* [`pretty_env_logger`](https://docs.rs/pretty_env_logger/*/pretty_env_logger/)
|
||||
* [`stderrlog`](https://docs.rs/stderrlog/*/stderrlog/)
|
||||
* [`flexi_logger`](https://docs.rs/flexi_logger/*/flexi_logger/)
|
||||
* [`call_logger`](https://docs.rs/call_logger/*/call_logger/)
|
||||
* [`std-logger`](https://docs.rs/std-logger/*/std_logger/)
|
||||
* [`structured-logger`](https://docs.rs/structured-logger/latest/structured_logger/)
|
||||
* Complex configurable frameworks:
|
||||
* [`log4rs`](https://docs.rs/log4rs/*/log4rs/)
|
||||
* [`fern`](https://docs.rs/fern/*/fern/)
|
||||
* Adaptors for other facilities:
|
||||
* [`syslog`](https://docs.rs/syslog/*/syslog/)
|
||||
* [`systemd-journal-logger`](https://docs.rs/systemd-journal-logger/*/systemd_journal_logger/)
|
||||
* [`slog-stdlog`](https://docs.rs/slog-stdlog/*/slog_stdlog/)
|
||||
* [`android_log`](https://docs.rs/android_log/*/android_log/)
|
||||
* [`win_dbg_logger`](https://docs.rs/win_dbg_logger/*/win_dbg_logger/)
|
||||
* [`db_logger`](https://docs.rs/db_logger/*/db_logger/)
|
||||
* [`log-to-defmt`](https://docs.rs/log-to-defmt/*/log_to_defmt/)
|
||||
* For WebAssembly binaries:
|
||||
* [`console_log`](https://docs.rs/console_log/*/console_log/)
|
||||
* For dynamic libraries:
|
||||
* You may need to construct [an FFI-safe wrapper over `log`](https://github.com/rust-lang/log/issues/421) to initialize in your libraries.
|
||||
* Utilities:
|
||||
* [`log_err`](https://docs.rs/log_err/*/log_err/)
|
||||
|
||||
Executables should choose a logger implementation and initialize it early in the
|
||||
runtime of the program. Logger implementations will typically include a
|
||||
function to do this. Any log messages generated before the logger is
|
||||
initialized will be ignored.
|
||||
|
||||
The executable itself may use the `log` crate to log as well.
|
||||
|
||||
## Structured logging
|
||||
|
||||
If you enable the `kv_unstable` feature, you can associate structured data with your log records:
|
||||
|
||||
```rust
|
||||
use log::{info, trace, warn, as_serde, as_error};
|
||||
|
||||
pub fn shave_the_yak(yak: &mut Yak) {
|
||||
trace!(target = "yak_events", yak = as_serde!(yak); "Commencing yak shaving");
|
||||
|
||||
loop {
|
||||
match find_a_razor() {
|
||||
Ok(razor) => {
|
||||
info!(razor = razor; "Razor located");
|
||||
yak.shave(razor);
|
||||
break;
|
||||
}
|
||||
Err(err) => {
|
||||
warn!(err = as_error!(err); "Unable to locate a razor, retrying");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
30
vendor/log/benches/value.rs
vendored
Normal file
30
vendor/log/benches/value.rs
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
#![cfg(feature = "kv_unstable")]
|
||||
#![feature(test)]
|
||||
|
||||
extern crate log;
|
||||
extern crate test;
|
||||
|
||||
use log::kv::Value;
|
||||
|
||||
#[bench]
|
||||
fn u8_to_value(b: &mut test::Bencher) {
|
||||
b.iter(|| Value::from(1u8))
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn u8_to_value_debug(b: &mut test::Bencher) {
|
||||
b.iter(|| Value::from_debug(&1u8))
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn str_to_value_debug(b: &mut test::Bencher) {
|
||||
b.iter(|| Value::from_debug(&"a string"))
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn custom_to_value_debug(b: &mut test::Bencher) {
|
||||
#[derive(Debug)]
|
||||
struct A;
|
||||
|
||||
b.iter(|| Value::from_debug(&A))
|
||||
}
|
57
vendor/log/src/__private_api.rs
vendored
Normal file
57
vendor/log/src/__private_api.rs
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
//! WARNING: this is not part of the crate's public API and is subject to change at any time
|
||||
|
||||
use crate::{Level, Metadata, Record};
|
||||
use std::fmt::Arguments;
|
||||
pub use std::option::Option;
|
||||
pub use std::{file, format_args, line, module_path, stringify};
|
||||
|
||||
#[cfg(not(feature = "kv_unstable"))]
|
||||
pub fn log(
|
||||
args: Arguments,
|
||||
level: Level,
|
||||
&(target, module_path, file): &(&str, &'static str, &'static str),
|
||||
line: u32,
|
||||
kvs: Option<&[(&str, &str)]>,
|
||||
) {
|
||||
if kvs.is_some() {
|
||||
panic!(
|
||||
"key-value support is experimental and must be enabled using the `kv_unstable` feature"
|
||||
)
|
||||
}
|
||||
|
||||
crate::logger().log(
|
||||
&Record::builder()
|
||||
.args(args)
|
||||
.level(level)
|
||||
.target(target)
|
||||
.module_path_static(Some(module_path))
|
||||
.file_static(Some(file))
|
||||
.line(Some(line))
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "kv_unstable")]
|
||||
pub fn log(
|
||||
args: Arguments,
|
||||
level: Level,
|
||||
&(target, module_path, file): &(&str, &'static str, &'static str),
|
||||
line: u32,
|
||||
kvs: Option<&[(&str, &dyn crate::kv::ToValue)]>,
|
||||
) {
|
||||
crate::logger().log(
|
||||
&Record::builder()
|
||||
.args(args)
|
||||
.level(level)
|
||||
.target(target)
|
||||
.module_path_static(Some(module_path))
|
||||
.file_static(Some(file))
|
||||
.line(Some(line))
|
||||
.key_values(&kvs)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn enabled(level: Level, target: &str) -> bool {
|
||||
crate::logger().enabled(&Metadata::builder().level(level).target(target).build())
|
||||
}
|
90
vendor/log/src/kv/error.rs
vendored
Normal file
90
vendor/log/src/kv/error.rs
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
use std::fmt;
|
||||
|
||||
/// An error encountered while working with structured data.
|
||||
#[derive(Debug)]
|
||||
pub struct Error {
|
||||
inner: Inner,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Inner {
|
||||
#[cfg(feature = "std")]
|
||||
Boxed(std_support::BoxedError),
|
||||
Msg(&'static str),
|
||||
Value(value_bag::Error),
|
||||
Fmt,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
/// Create an error from a message.
|
||||
pub fn msg(msg: &'static str) -> Self {
|
||||
Error {
|
||||
inner: Inner::Msg(msg),
|
||||
}
|
||||
}
|
||||
|
||||
// Not public so we don't leak the `value_bag` API
|
||||
pub(super) fn from_value(err: value_bag::Error) -> Self {
|
||||
Error {
|
||||
inner: Inner::Value(err),
|
||||
}
|
||||
}
|
||||
|
||||
// Not public so we don't leak the `value_bag` API
|
||||
pub(super) fn into_value(self) -> value_bag::Error {
|
||||
match self.inner {
|
||||
Inner::Value(err) => err,
|
||||
#[cfg(feature = "kv_unstable_std")]
|
||||
_ => value_bag::Error::boxed(self),
|
||||
#[cfg(not(feature = "kv_unstable_std"))]
|
||||
_ => value_bag::Error::msg("error inspecting a value"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::Inner::*;
|
||||
match &self.inner {
|
||||
#[cfg(feature = "std")]
|
||||
&Boxed(ref err) => err.fmt(f),
|
||||
&Value(ref err) => err.fmt(f),
|
||||
&Msg(ref msg) => msg.fmt(f),
|
||||
&Fmt => fmt::Error.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<fmt::Error> for Error {
|
||||
fn from(_: fmt::Error) -> Self {
|
||||
Error { inner: Inner::Fmt }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
mod std_support {
|
||||
use super::*;
|
||||
use std::{error, io};
|
||||
|
||||
pub(super) type BoxedError = Box<dyn error::Error + Send + Sync>;
|
||||
|
||||
impl Error {
|
||||
/// Create an error from a standard error type.
|
||||
pub fn boxed<E>(err: E) -> Self
|
||||
where
|
||||
E: Into<BoxedError>,
|
||||
{
|
||||
Error {
|
||||
inner: Inner::Boxed(err.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl error::Error for Error {}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(err: io::Error) -> Self {
|
||||
Error::boxed(err)
|
||||
}
|
||||
}
|
||||
}
|
157
vendor/log/src/kv/key.rs
vendored
Normal file
157
vendor/log/src/kv/key.rs
vendored
Normal file
@ -0,0 +1,157 @@
|
||||
//! Structured keys.
|
||||
|
||||
use std::borrow::Borrow;
|
||||
use std::fmt;
|
||||
|
||||
/// A type that can be converted into a [`Key`](struct.Key.html).
|
||||
pub trait ToKey {
|
||||
/// Perform the conversion.
|
||||
fn to_key(&self) -> Key;
|
||||
}
|
||||
|
||||
impl<'a, T> ToKey for &'a T
|
||||
where
|
||||
T: ToKey + ?Sized,
|
||||
{
|
||||
fn to_key(&self) -> Key {
|
||||
(**self).to_key()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'k> ToKey for Key<'k> {
|
||||
fn to_key(&self) -> Key {
|
||||
Key { key: self.key }
|
||||
}
|
||||
}
|
||||
|
||||
impl ToKey for str {
|
||||
fn to_key(&self) -> Key {
|
||||
Key::from_str(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// A key in a structured key-value pair.
|
||||
// These impls must only be based on the as_str() representation of the key
|
||||
// If a new field (such as an optional index) is added to the key they must not affect comparison
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct Key<'k> {
|
||||
key: &'k str,
|
||||
}
|
||||
|
||||
impl<'k> Key<'k> {
|
||||
/// Get a key from a borrowed string.
|
||||
pub fn from_str(key: &'k str) -> Self {
|
||||
Key { key }
|
||||
}
|
||||
|
||||
/// Get a borrowed string from this key.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.key
|
||||
}
|
||||
|
||||
/// Try get a string borrowed for the `'k` lifetime from this key.
|
||||
pub fn to_borrowed_str(&self) -> Option<&'k str> {
|
||||
// NOTE: This API leaves room for keys to be owned
|
||||
Some(self.key)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'k> fmt::Display for Key<'k> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.key.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'k> AsRef<str> for Key<'k> {
|
||||
fn as_ref(&self) -> &str {
|
||||
self.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'k> Borrow<str> for Key<'k> {
|
||||
fn borrow(&self) -> &str {
|
||||
self.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'k> From<&'k str> for Key<'k> {
|
||||
fn from(s: &'k str) -> Self {
|
||||
Key::from_str(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
mod std_support {
|
||||
use super::*;
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
impl ToKey for String {
|
||||
fn to_key(&self) -> Key {
|
||||
Key::from_str(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ToKey for Cow<'a, str> {
|
||||
fn to_key(&self) -> Key {
|
||||
Key::from_str(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "kv_unstable_sval")]
|
||||
mod sval_support {
|
||||
use super::*;
|
||||
|
||||
extern crate sval;
|
||||
extern crate sval_ref;
|
||||
|
||||
use self::sval::Value;
|
||||
use self::sval_ref::ValueRef;
|
||||
|
||||
impl<'a> Value for Key<'a> {
|
||||
fn stream<'sval, S: sval::Stream<'sval> + ?Sized>(
|
||||
&'sval self,
|
||||
stream: &mut S,
|
||||
) -> sval::Result {
|
||||
self.key.stream(stream)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ValueRef<'a> for Key<'a> {
|
||||
fn stream_ref<S: self::sval::Stream<'a> + ?Sized>(
|
||||
&self,
|
||||
stream: &mut S,
|
||||
) -> self::sval::Result {
|
||||
self.key.stream(stream)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "kv_unstable_serde")]
|
||||
mod serde_support {
|
||||
use super::*;
|
||||
|
||||
extern crate serde;
|
||||
|
||||
use self::serde::{Serialize, Serializer};
|
||||
|
||||
impl<'a> Serialize for Key<'a> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
self.key.serialize(serializer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn key_from_string() {
|
||||
assert_eq!("a key", Key::from_str("a key").as_str());
|
||||
}
|
||||
}
|
26
vendor/log/src/kv/mod.rs
vendored
Normal file
26
vendor/log/src/kv/mod.rs
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
//! **UNSTABLE:** Structured key-value pairs.
|
||||
//!
|
||||
//! This module is unstable and breaking changes may be made
|
||||
//! at any time. See [the tracking issue](https://github.com/rust-lang-nursery/log/issues/328)
|
||||
//! for more details.
|
||||
//!
|
||||
//! Add the `kv_unstable` feature to your `Cargo.toml` to enable
|
||||
//! this module:
|
||||
//!
|
||||
//! ```toml
|
||||
//! [dependencies.log]
|
||||
//! features = ["kv_unstable"]
|
||||
//! ```
|
||||
|
||||
mod error;
|
||||
mod key;
|
||||
pub mod source;
|
||||
|
||||
pub mod value;
|
||||
|
||||
pub use self::error::Error;
|
||||
pub use self::key::{Key, ToKey};
|
||||
pub use self::source::{Source, Visitor};
|
||||
|
||||
#[doc(inline)]
|
||||
pub use self::value::{ToValue, Value};
|
776
vendor/log/src/kv/source.rs
vendored
Normal file
776
vendor/log/src/kv/source.rs
vendored
Normal file
@ -0,0 +1,776 @@
|
||||
//! Sources for key-value pairs.
|
||||
|
||||
#[cfg(feature = "kv_unstable_sval")]
|
||||
extern crate sval;
|
||||
#[cfg(feature = "kv_unstable_sval")]
|
||||
extern crate sval_ref;
|
||||
|
||||
#[cfg(feature = "kv_unstable_serde")]
|
||||
extern crate serde;
|
||||
|
||||
use kv::{Error, Key, ToKey, ToValue, Value};
|
||||
use std::fmt;
|
||||
|
||||
/// A source of key-value pairs.
|
||||
///
|
||||
/// The source may be a single pair, a set of pairs, or a filter over a set of pairs.
|
||||
/// Use the [`Visitor`](trait.Visitor.html) trait to inspect the structured data
|
||||
/// in a source.
|
||||
pub trait Source {
|
||||
/// Visit key-value pairs.
|
||||
///
|
||||
/// A source doesn't have to guarantee any ordering or uniqueness of key-value pairs.
|
||||
/// If the given visitor returns an error then the source may early-return with it,
|
||||
/// even if there are more key-value pairs.
|
||||
///
|
||||
/// # Implementation notes
|
||||
///
|
||||
/// A source should yield the same key-value pairs to a subsequent visitor unless
|
||||
/// that visitor itself fails.
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn Visitor<'kvs>) -> Result<(), Error>;
|
||||
|
||||
/// Get the value for a given key.
|
||||
///
|
||||
/// If the key appears multiple times in the source then which key is returned
|
||||
/// is implementation specific.
|
||||
///
|
||||
/// # Implementation notes
|
||||
///
|
||||
/// A source that can provide a more efficient implementation of this method
|
||||
/// should override it.
|
||||
#[cfg(not(test))]
|
||||
fn get<'v>(&'v self, key: Key) -> Option<Value<'v>> {
|
||||
get_default(self, key)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn get<'v>(&'v self, key: Key) -> Option<Value<'v>>;
|
||||
|
||||
/// Count the number of key-value pairs that can be visited.
|
||||
///
|
||||
/// # Implementation notes
|
||||
///
|
||||
/// A source that knows the number of key-value pairs upfront may provide a more
|
||||
/// efficient implementation.
|
||||
///
|
||||
/// A subsequent call to `visit` should yield the same number of key-value pairs
|
||||
/// to the visitor, unless that visitor fails part way through.
|
||||
#[cfg(not(test))]
|
||||
fn count(&self) -> usize {
|
||||
count_default(self)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn count(&self) -> usize;
|
||||
}
|
||||
|
||||
/// The default implemention of `Source::get`
|
||||
pub(crate) fn get_default<'v>(source: &'v (impl Source + ?Sized), key: Key) -> Option<Value<'v>> {
|
||||
struct Get<'k, 'v> {
|
||||
key: Key<'k>,
|
||||
found: Option<Value<'v>>,
|
||||
}
|
||||
|
||||
impl<'k, 'kvs> Visitor<'kvs> for Get<'k, 'kvs> {
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
if self.key == key {
|
||||
self.found = Some(value);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
let mut get = Get { key, found: None };
|
||||
|
||||
let _ = source.visit(&mut get);
|
||||
get.found
|
||||
}
|
||||
|
||||
/// The default implementation of `Source::count`.
|
||||
pub(crate) fn count_default(source: impl Source) -> usize {
|
||||
struct Count(usize);
|
||||
|
||||
impl<'kvs> Visitor<'kvs> for Count {
|
||||
fn visit_pair(&mut self, _: Key<'kvs>, _: Value<'kvs>) -> Result<(), Error> {
|
||||
self.0 += 1;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
let mut count = Count(0);
|
||||
let _ = source.visit(&mut count);
|
||||
count.0
|
||||
}
|
||||
|
||||
impl<'a, T> Source for &'a T
|
||||
where
|
||||
T: Source + ?Sized,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn Visitor<'kvs>) -> Result<(), Error> {
|
||||
Source::visit(&**self, visitor)
|
||||
}
|
||||
|
||||
fn get<'v>(&'v self, key: Key) -> Option<Value<'v>> {
|
||||
Source::get(&**self, key)
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
Source::count(&**self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> Source for (K, V)
|
||||
where
|
||||
K: ToKey,
|
||||
V: ToValue,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn Visitor<'kvs>) -> Result<(), Error> {
|
||||
visitor.visit_pair(self.0.to_key(), self.1.to_value())
|
||||
}
|
||||
|
||||
fn get<'v>(&'v self, key: Key) -> Option<Value<'v>> {
|
||||
if self.0.to_key() == key {
|
||||
Some(self.1.to_value())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Source for [S]
|
||||
where
|
||||
S: Source,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn Visitor<'kvs>) -> Result<(), Error> {
|
||||
for source in self {
|
||||
source.visit(visitor)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get<'v>(&'v self, key: Key) -> Option<Value<'v>> {
|
||||
for source in self {
|
||||
if let Some(found) = source.get(key.clone()) {
|
||||
return Some(found);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
self.len()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Source for Option<S>
|
||||
where
|
||||
S: Source,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn Visitor<'kvs>) -> Result<(), Error> {
|
||||
if let Some(ref source) = *self {
|
||||
source.visit(visitor)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get<'v>(&'v self, key: Key) -> Option<Value<'v>> {
|
||||
self.as_ref().and_then(|s| s.get(key))
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
self.as_ref().map(Source::count).unwrap_or(0)
|
||||
}
|
||||
}
|
||||
|
||||
/// A visitor for the key-value pairs in a [`Source`](trait.Source.html).
|
||||
pub trait Visitor<'kvs> {
|
||||
/// Visit a key-value pair.
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
impl<'a, 'kvs, T> Visitor<'kvs> for &'a mut T
|
||||
where
|
||||
T: Visitor<'kvs> + ?Sized,
|
||||
{
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
(**self).visit_pair(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b: 'a, 'kvs> Visitor<'kvs> for fmt::DebugMap<'a, 'b> {
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
self.entry(&key, &value);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b: 'a, 'kvs> Visitor<'kvs> for fmt::DebugList<'a, 'b> {
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
self.entry(&(key, value));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b: 'a, 'kvs> Visitor<'kvs> for fmt::DebugSet<'a, 'b> {
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
self.entry(&(key, value));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b: 'a, 'kvs> Visitor<'kvs> for fmt::DebugTuple<'a, 'b> {
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
self.field(&key);
|
||||
self.field(&value);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
mod std_support {
|
||||
use super::*;
|
||||
use std::borrow::Borrow;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::hash::{BuildHasher, Hash};
|
||||
|
||||
impl<S> Source for Box<S>
|
||||
where
|
||||
S: Source + ?Sized,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn Visitor<'kvs>) -> Result<(), Error> {
|
||||
Source::visit(&**self, visitor)
|
||||
}
|
||||
|
||||
fn get<'v>(&'v self, key: Key) -> Option<Value<'v>> {
|
||||
Source::get(&**self, key)
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
Source::count(&**self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Source for Vec<S>
|
||||
where
|
||||
S: Source,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn Visitor<'kvs>) -> Result<(), Error> {
|
||||
Source::visit(&**self, visitor)
|
||||
}
|
||||
|
||||
fn get<'v>(&'v self, key: Key) -> Option<Value<'v>> {
|
||||
Source::get(&**self, key)
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
Source::count(&**self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'kvs, V> Visitor<'kvs> for Box<V>
|
||||
where
|
||||
V: Visitor<'kvs> + ?Sized,
|
||||
{
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
(**self).visit_pair(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V, S> Source for HashMap<K, V, S>
|
||||
where
|
||||
K: ToKey + Borrow<str> + Eq + Hash,
|
||||
V: ToValue,
|
||||
S: BuildHasher,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn Visitor<'kvs>) -> Result<(), Error> {
|
||||
for (key, value) in self {
|
||||
visitor.visit_pair(key.to_key(), value.to_value())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get<'v>(&'v self, key: Key) -> Option<Value<'v>> {
|
||||
HashMap::get(self, key.as_str()).map(|v| v.to_value())
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
self.len()
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> Source for BTreeMap<K, V>
|
||||
where
|
||||
K: ToKey + Borrow<str> + Ord,
|
||||
V: ToValue,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn Visitor<'kvs>) -> Result<(), Error> {
|
||||
for (key, value) in self {
|
||||
visitor.visit_pair(key.to_key(), value.to_value())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get<'v>(&'v self, key: Key) -> Option<Value<'v>> {
|
||||
BTreeMap::get(self, key.as_str()).map(|v| v.to_value())
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
self.len()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use kv::value::tests::Token;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
|
||||
#[test]
|
||||
fn count() {
|
||||
assert_eq!(1, Source::count(&Box::new(("a", 1))));
|
||||
assert_eq!(2, Source::count(&vec![("a", 1), ("b", 2)]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get() {
|
||||
let source = vec![("a", 1), ("b", 2), ("a", 1)];
|
||||
assert_eq!(
|
||||
Token::I64(1),
|
||||
Source::get(&source, Key::from_str("a")).unwrap().to_token()
|
||||
);
|
||||
|
||||
let source = Box::new(Option::None::<(&str, i32)>);
|
||||
assert!(Source::get(&source, Key::from_str("a")).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_map() {
|
||||
let mut map = HashMap::new();
|
||||
map.insert("a", 1);
|
||||
map.insert("b", 2);
|
||||
|
||||
assert_eq!(2, Source::count(&map));
|
||||
assert_eq!(
|
||||
Token::I64(1),
|
||||
Source::get(&map, Key::from_str("a")).unwrap().to_token()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn btree_map() {
|
||||
let mut map = BTreeMap::new();
|
||||
map.insert("a", 1);
|
||||
map.insert("b", 2);
|
||||
|
||||
assert_eq!(2, Source::count(&map));
|
||||
assert_eq!(
|
||||
Token::I64(1),
|
||||
Source::get(&map, Key::from_str("a")).unwrap().to_token()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The result of calling `Source::as_map`.
|
||||
pub struct AsMap<S>(S);
|
||||
|
||||
/// Visit this source as a map.
|
||||
pub fn as_map<S>(source: S) -> AsMap<S>
|
||||
where
|
||||
S: Source,
|
||||
{
|
||||
AsMap(source)
|
||||
}
|
||||
|
||||
impl<S> Source for AsMap<S>
|
||||
where
|
||||
S: Source,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn Visitor<'kvs>) -> Result<(), Error> {
|
||||
self.0.visit(visitor)
|
||||
}
|
||||
|
||||
fn get<'v>(&'v self, key: Key) -> Option<Value<'v>> {
|
||||
self.0.get(key)
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
self.0.count()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> fmt::Debug for AsMap<S>
|
||||
where
|
||||
S: Source,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let mut f = f.debug_map();
|
||||
self.0.visit(&mut f).map_err(|_| fmt::Error)?;
|
||||
f.finish()
|
||||
}
|
||||
}
|
||||
|
||||
/// The result of calling `Source::as_list`
|
||||
pub struct AsList<S>(S);
|
||||
|
||||
/// Visit this source as a list.
|
||||
pub fn as_list<S>(source: S) -> AsList<S>
|
||||
where
|
||||
S: Source,
|
||||
{
|
||||
AsList(source)
|
||||
}
|
||||
|
||||
impl<S> Source for AsList<S>
|
||||
where
|
||||
S: Source,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn Visitor<'kvs>) -> Result<(), Error> {
|
||||
self.0.visit(visitor)
|
||||
}
|
||||
|
||||
fn get<'v>(&'v self, key: Key) -> Option<Value<'v>> {
|
||||
self.0.get(key)
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
self.0.count()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> fmt::Debug for AsList<S>
|
||||
where
|
||||
S: Source,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let mut f = f.debug_list();
|
||||
self.0.visit(&mut f).map_err(|_| fmt::Error)?;
|
||||
f.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "kv_unstable_sval")]
|
||||
mod sval_support {
|
||||
use super::*;
|
||||
|
||||
impl<S> self::sval::Value for AsMap<S>
|
||||
where
|
||||
S: Source,
|
||||
{
|
||||
fn stream<'sval, SV: self::sval::Stream<'sval> + ?Sized>(
|
||||
&'sval self,
|
||||
stream: &mut SV,
|
||||
) -> self::sval::Result {
|
||||
struct StreamVisitor<'a, V: ?Sized>(&'a mut V);
|
||||
|
||||
impl<'a, 'kvs, V: self::sval::Stream<'kvs> + ?Sized> Visitor<'kvs> for StreamVisitor<'a, V> {
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
self.0
|
||||
.map_key_begin()
|
||||
.map_err(|_| Error::msg("failed to stream map key"))?;
|
||||
sval_ref::stream_ref(self.0, key)
|
||||
.map_err(|_| Error::msg("failed to stream map key"))?;
|
||||
self.0
|
||||
.map_key_end()
|
||||
.map_err(|_| Error::msg("failed to stream map key"))?;
|
||||
|
||||
self.0
|
||||
.map_value_begin()
|
||||
.map_err(|_| Error::msg("failed to stream map value"))?;
|
||||
sval_ref::stream_ref(self.0, value)
|
||||
.map_err(|_| Error::msg("failed to stream map value"))?;
|
||||
self.0
|
||||
.map_value_end()
|
||||
.map_err(|_| Error::msg("failed to stream map value"))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
stream
|
||||
.map_begin(Some(self.count()))
|
||||
.map_err(|_| self::sval::Error::new())?;
|
||||
|
||||
self.visit(&mut StreamVisitor(stream))
|
||||
.map_err(|_| self::sval::Error::new())?;
|
||||
|
||||
stream.map_end().map_err(|_| self::sval::Error::new())
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> self::sval::Value for AsList<S>
|
||||
where
|
||||
S: Source,
|
||||
{
|
||||
fn stream<'sval, SV: self::sval::Stream<'sval> + ?Sized>(
|
||||
&'sval self,
|
||||
stream: &mut SV,
|
||||
) -> self::sval::Result {
|
||||
struct StreamVisitor<'a, V: ?Sized>(&'a mut V);
|
||||
|
||||
impl<'a, 'kvs, V: self::sval::Stream<'kvs> + ?Sized> Visitor<'kvs> for StreamVisitor<'a, V> {
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
self.0
|
||||
.seq_value_begin()
|
||||
.map_err(|_| Error::msg("failed to stream seq value"))?;
|
||||
self::sval_ref::stream_ref(self.0, (key, value))
|
||||
.map_err(|_| Error::msg("failed to stream seq value"))?;
|
||||
self.0
|
||||
.seq_value_end()
|
||||
.map_err(|_| Error::msg("failed to stream seq value"))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
stream
|
||||
.seq_begin(Some(self.count()))
|
||||
.map_err(|_| self::sval::Error::new())?;
|
||||
|
||||
self.visit(&mut StreamVisitor(stream))
|
||||
.map_err(|_| self::sval::Error::new())?;
|
||||
|
||||
stream.seq_end().map_err(|_| self::sval::Error::new())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate sval_derive;
|
||||
|
||||
use super::*;
|
||||
|
||||
use self::sval_derive::Value;
|
||||
|
||||
use crate::kv::source;
|
||||
|
||||
#[test]
|
||||
fn derive_stream() {
|
||||
#[derive(Value)]
|
||||
pub struct MyRecordAsMap<'a> {
|
||||
msg: &'a str,
|
||||
kvs: source::AsMap<&'a dyn Source>,
|
||||
}
|
||||
|
||||
#[derive(Value)]
|
||||
pub struct MyRecordAsList<'a> {
|
||||
msg: &'a str,
|
||||
kvs: source::AsList<&'a dyn Source>,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "kv_unstable_serde")]
|
||||
pub mod as_map {
|
||||
//! `serde` adapters for serializing a `Source` as a map.
|
||||
|
||||
use super::*;
|
||||
|
||||
use self::serde::{Serialize, Serializer};
|
||||
|
||||
/// Serialize a `Source` as a map.
|
||||
pub fn serialize<T, S>(source: &T, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
T: Source,
|
||||
S: Serializer,
|
||||
{
|
||||
as_map(source).serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "kv_unstable_serde")]
|
||||
pub mod as_list {
|
||||
//! `serde` adapters for serializing a `Source` as a list.
|
||||
|
||||
use super::*;
|
||||
|
||||
use self::serde::{Serialize, Serializer};
|
||||
|
||||
/// Serialize a `Source` as a list.
|
||||
pub fn serialize<T, S>(source: &T, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
T: Source,
|
||||
S: Serializer,
|
||||
{
|
||||
as_list(source).serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "kv_unstable_serde")]
|
||||
mod serde_support {
|
||||
use super::*;
|
||||
|
||||
use self::serde::ser::{Error as SerError, Serialize, SerializeMap, SerializeSeq, Serializer};
|
||||
|
||||
impl<T> Serialize for AsMap<T>
|
||||
where
|
||||
T: Source,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
struct SerializerVisitor<'a, S>(&'a mut S);
|
||||
|
||||
impl<'a, 'kvs, S> Visitor<'kvs> for SerializerVisitor<'a, S>
|
||||
where
|
||||
S: SerializeMap,
|
||||
{
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
self.0
|
||||
.serialize_entry(&key, &value)
|
||||
.map_err(|_| Error::msg("failed to serialize map entry"))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
let mut map = serializer.serialize_map(Some(self.count()))?;
|
||||
|
||||
self.visit(&mut SerializerVisitor(&mut map))
|
||||
.map_err(|_| S::Error::custom("failed to visit key-values"))?;
|
||||
|
||||
map.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Serialize for AsList<T>
|
||||
where
|
||||
T: Source,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
struct SerializerVisitor<'a, S>(&'a mut S);
|
||||
|
||||
impl<'a, 'kvs, S> Visitor<'kvs> for SerializerVisitor<'a, S>
|
||||
where
|
||||
S: SerializeSeq,
|
||||
{
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
self.0
|
||||
.serialize_element(&(key, value))
|
||||
.map_err(|_| Error::msg("failed to serialize seq entry"))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
let mut seq = serializer.serialize_seq(Some(self.count()))?;
|
||||
|
||||
self.visit(&mut SerializerVisitor(&mut seq))
|
||||
.map_err(|_| S::Error::custom("failed to visit seq"))?;
|
||||
|
||||
seq.end()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use self::serde::Serialize;
|
||||
|
||||
use crate::kv::source;
|
||||
|
||||
#[test]
|
||||
fn derive_serialize() {
|
||||
#[derive(Serialize)]
|
||||
pub struct MyRecordAsMap<'a> {
|
||||
msg: &'a str,
|
||||
#[serde(flatten)]
|
||||
#[serde(with = "source::as_map")]
|
||||
kvs: &'a dyn Source,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct MyRecordAsList<'a> {
|
||||
msg: &'a str,
|
||||
#[serde(flatten)]
|
||||
#[serde(with = "source::as_list")]
|
||||
kvs: &'a dyn Source,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use kv::value::tests::Token;
|
||||
|
||||
#[test]
|
||||
fn source_is_object_safe() {
|
||||
fn _check(_: &dyn Source) {}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn visitor_is_object_safe() {
|
||||
fn _check(_: &dyn Visitor) {}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn count() {
|
||||
struct OnePair {
|
||||
key: &'static str,
|
||||
value: i32,
|
||||
}
|
||||
|
||||
impl Source for OnePair {
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn Visitor<'kvs>) -> Result<(), Error> {
|
||||
visitor.visit_pair(self.key.to_key(), self.value.to_value())
|
||||
}
|
||||
|
||||
fn get<'v>(&'v self, key: Key) -> Option<Value<'v>> {
|
||||
get_default(self, key)
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
count_default(self)
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(1, Source::count(&("a", 1)));
|
||||
assert_eq!(2, Source::count(&[("a", 1), ("b", 2)] as &[_]));
|
||||
assert_eq!(0, Source::count(&Option::None::<(&str, i32)>));
|
||||
assert_eq!(1, Source::count(&OnePair { key: "a", value: 1 }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get() {
|
||||
let source = &[("a", 1), ("b", 2), ("a", 1)] as &[_];
|
||||
assert_eq!(
|
||||
Token::I64(1),
|
||||
Source::get(source, Key::from_str("a")).unwrap().to_token()
|
||||
);
|
||||
assert_eq!(
|
||||
Token::I64(2),
|
||||
Source::get(source, Key::from_str("b")).unwrap().to_token()
|
||||
);
|
||||
assert!(Source::get(&source, Key::from_str("c")).is_none());
|
||||
|
||||
let source = Option::None::<(&str, i32)>;
|
||||
assert!(Source::get(&source, Key::from_str("a")).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn as_map() {
|
||||
let _ = crate::kv::source::as_map(("a", 1));
|
||||
let _ = crate::kv::source::as_map(&("a", 1) as &dyn Source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn as_list() {
|
||||
let _ = crate::kv::source::as_list(("a", 1));
|
||||
let _ = crate::kv::source::as_list(&("a", 1) as &dyn Source);
|
||||
}
|
||||
}
|
1031
vendor/log/src/kv/value.rs
vendored
Normal file
1031
vendor/log/src/kv/value.rs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1827
vendor/log/src/lib.rs
vendored
Normal file
1827
vendor/log/src/lib.rs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
240
vendor/log/src/macros.rs
vendored
Normal file
240
vendor/log/src/macros.rs
vendored
Normal file
@ -0,0 +1,240 @@
|
||||
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
/// The standard logging macro.
|
||||
///
|
||||
/// This macro will generically log with the specified `Level` and `format!`
|
||||
/// based argument list.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```edition2018
|
||||
/// use log::{log, Level};
|
||||
///
|
||||
/// # fn main() {
|
||||
/// let data = (42, "Forty-two");
|
||||
/// let private_data = "private";
|
||||
///
|
||||
/// log!(Level::Error, "Received errors: {}, {}", data.0, data.1);
|
||||
/// log!(target: "app_events", Level::Warn, "App warning: {}, {}, {}",
|
||||
/// data.0, data.1, private_data);
|
||||
/// # }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! log {
|
||||
// log!(target: "my_target", Level::Info, key1 = 42, key2 = true; "a {} event", "log");
|
||||
(target: $target:expr, $lvl:expr, $($key:tt = $value:expr),+; $($arg:tt)+) => ({
|
||||
let lvl = $lvl;
|
||||
if lvl <= $crate::STATIC_MAX_LEVEL && lvl <= $crate::max_level() {
|
||||
$crate::__private_api::log(
|
||||
$crate::__private_api::format_args!($($arg)+),
|
||||
lvl,
|
||||
&($target, $crate::__private_api::module_path!(), $crate::__private_api::file!()),
|
||||
$crate::__private_api::line!(),
|
||||
$crate::__private_api::Option::Some(&[$(($crate::__log_key!($key), &$value)),+])
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// log!(target: "my_target", Level::Info, "a {} event", "log");
|
||||
(target: $target:expr, $lvl:expr, $($arg:tt)+) => ({
|
||||
let lvl = $lvl;
|
||||
if lvl <= $crate::STATIC_MAX_LEVEL && lvl <= $crate::max_level() {
|
||||
$crate::__private_api::log(
|
||||
$crate::__private_api::format_args!($($arg)+),
|
||||
lvl,
|
||||
&($target, $crate::__private_api::module_path!(), $crate::__private_api::file!()),
|
||||
$crate::__private_api::line!(),
|
||||
$crate::__private_api::Option::None,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// log!(Level::Info, "a log event")
|
||||
($lvl:expr, $($arg:tt)+) => ($crate::log!(target: $crate::__private_api::module_path!(), $lvl, $($arg)+));
|
||||
}
|
||||
|
||||
/// Logs a message at the error level.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```edition2018
|
||||
/// use log::error;
|
||||
///
|
||||
/// # fn main() {
|
||||
/// let (err_info, port) = ("No connection", 22);
|
||||
///
|
||||
/// error!("Error: {} on port {}", err_info, port);
|
||||
/// error!(target: "app_events", "App Error: {}, Port: {}", err_info, 22);
|
||||
/// # }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! error {
|
||||
// error!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
|
||||
// error!(target: "my_target", "a {} event", "log")
|
||||
(target: $target:expr, $($arg:tt)+) => ($crate::log!(target: $target, $crate::Level::Error, $($arg)+));
|
||||
|
||||
// error!("a {} event", "log")
|
||||
($($arg:tt)+) => ($crate::log!($crate::Level::Error, $($arg)+))
|
||||
}
|
||||
|
||||
/// Logs a message at the warn level.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```edition2018
|
||||
/// use log::warn;
|
||||
///
|
||||
/// # fn main() {
|
||||
/// let warn_description = "Invalid Input";
|
||||
///
|
||||
/// warn!("Warning! {}!", warn_description);
|
||||
/// warn!(target: "input_events", "App received warning: {}", warn_description);
|
||||
/// # }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! warn {
|
||||
// warn!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
|
||||
// warn!(target: "my_target", "a {} event", "log")
|
||||
(target: $target:expr, $($arg:tt)+) => ($crate::log!(target: $target, $crate::Level::Warn, $($arg)+));
|
||||
|
||||
// warn!("a {} event", "log")
|
||||
($($arg:tt)+) => ($crate::log!($crate::Level::Warn, $($arg)+))
|
||||
}
|
||||
|
||||
/// Logs a message at the info level.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```edition2018
|
||||
/// use log::info;
|
||||
///
|
||||
/// # fn main() {
|
||||
/// # struct Connection { port: u32, speed: f32 }
|
||||
/// let conn_info = Connection { port: 40, speed: 3.20 };
|
||||
///
|
||||
/// info!("Connected to port {} at {} Mb/s", conn_info.port, conn_info.speed);
|
||||
/// info!(target: "connection_events", "Successful connection, port: {}, speed: {}",
|
||||
/// conn_info.port, conn_info.speed);
|
||||
/// # }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! info {
|
||||
// info!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
|
||||
// info!(target: "my_target", "a {} event", "log")
|
||||
(target: $target:expr, $($arg:tt)+) => ($crate::log!(target: $target, $crate::Level::Info, $($arg)+));
|
||||
|
||||
// info!("a {} event", "log")
|
||||
($($arg:tt)+) => ($crate::log!($crate::Level::Info, $($arg)+))
|
||||
}
|
||||
|
||||
/// Logs a message at the debug level.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```edition2018
|
||||
/// use log::debug;
|
||||
///
|
||||
/// # fn main() {
|
||||
/// # struct Position { x: f32, y: f32 }
|
||||
/// let pos = Position { x: 3.234, y: -1.223 };
|
||||
///
|
||||
/// debug!("New position: x: {}, y: {}", pos.x, pos.y);
|
||||
/// debug!(target: "app_events", "New position: x: {}, y: {}", pos.x, pos.y);
|
||||
/// # }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! debug {
|
||||
// debug!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
|
||||
// debug!(target: "my_target", "a {} event", "log")
|
||||
(target: $target:expr, $($arg:tt)+) => ($crate::log!(target: $target, $crate::Level::Debug, $($arg)+));
|
||||
|
||||
// debug!("a {} event", "log")
|
||||
($($arg:tt)+) => ($crate::log!($crate::Level::Debug, $($arg)+))
|
||||
}
|
||||
|
||||
/// Logs a message at the trace level.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```edition2018
|
||||
/// use log::trace;
|
||||
///
|
||||
/// # fn main() {
|
||||
/// # struct Position { x: f32, y: f32 }
|
||||
/// let pos = Position { x: 3.234, y: -1.223 };
|
||||
///
|
||||
/// trace!("Position is: x: {}, y: {}", pos.x, pos.y);
|
||||
/// trace!(target: "app_events", "x is {} and y is {}",
|
||||
/// if pos.x >= 0.0 { "positive" } else { "negative" },
|
||||
/// if pos.y >= 0.0 { "positive" } else { "negative" });
|
||||
/// # }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! trace {
|
||||
// trace!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
|
||||
// trace!(target: "my_target", "a {} event", "log")
|
||||
(target: $target:expr, $($arg:tt)+) => ($crate::log!(target: $target, $crate::Level::Trace, $($arg)+));
|
||||
|
||||
// trace!("a {} event", "log")
|
||||
($($arg:tt)+) => ($crate::log!($crate::Level::Trace, $($arg)+))
|
||||
}
|
||||
|
||||
/// Determines if a message logged at the specified level in that module will
|
||||
/// be logged.
|
||||
///
|
||||
/// This can be used to avoid expensive computation of log message arguments if
|
||||
/// the message would be ignored anyway.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```edition2018
|
||||
/// use log::Level::Debug;
|
||||
/// use log::{debug, log_enabled};
|
||||
///
|
||||
/// # fn foo() {
|
||||
/// if log_enabled!(Debug) {
|
||||
/// let data = expensive_call();
|
||||
/// debug!("expensive debug data: {} {}", data.x, data.y);
|
||||
/// }
|
||||
/// if log_enabled!(target: "Global", Debug) {
|
||||
/// let data = expensive_call();
|
||||
/// debug!(target: "Global", "expensive debug data: {} {}", data.x, data.y);
|
||||
/// }
|
||||
/// # }
|
||||
/// # struct Data { x: u32, y: u32 }
|
||||
/// # fn expensive_call() -> Data { Data { x: 0, y: 0 } }
|
||||
/// # fn main() {}
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! log_enabled {
|
||||
(target: $target:expr, $lvl:expr) => {{
|
||||
let lvl = $lvl;
|
||||
lvl <= $crate::STATIC_MAX_LEVEL
|
||||
&& lvl <= $crate::max_level()
|
||||
&& $crate::__private_api::enabled(lvl, $target)
|
||||
}};
|
||||
($lvl:expr) => {
|
||||
$crate::log_enabled!(target: $crate::__private_api::module_path!(), $lvl)
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __log_key {
|
||||
// key1 = 42
|
||||
($($args:ident)*) => {
|
||||
$crate::__private_api::stringify!($($args)*)
|
||||
};
|
||||
// "key1" = 42
|
||||
($($args:expr)*) => {
|
||||
$($args)*
|
||||
};
|
||||
}
|
400
vendor/log/src/serde.rs
vendored
Normal file
400
vendor/log/src/serde.rs
vendored
Normal file
@ -0,0 +1,400 @@
|
||||
#![cfg(feature = "serde")]
|
||||
|
||||
extern crate serde;
|
||||
use self::serde::de::{
|
||||
Deserialize, DeserializeSeed, Deserializer, EnumAccess, Error, Unexpected, VariantAccess,
|
||||
Visitor,
|
||||
};
|
||||
use self::serde::ser::{Serialize, Serializer};
|
||||
|
||||
use {Level, LevelFilter, LOG_LEVEL_NAMES};
|
||||
|
||||
use std::fmt;
|
||||
use std::str::{self, FromStr};
|
||||
|
||||
// The Deserialize impls are handwritten to be case insensitive using FromStr.
|
||||
|
||||
impl Serialize for Level {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
match *self {
|
||||
Level::Error => serializer.serialize_unit_variant("Level", 0, "ERROR"),
|
||||
Level::Warn => serializer.serialize_unit_variant("Level", 1, "WARN"),
|
||||
Level::Info => serializer.serialize_unit_variant("Level", 2, "INFO"),
|
||||
Level::Debug => serializer.serialize_unit_variant("Level", 3, "DEBUG"),
|
||||
Level::Trace => serializer.serialize_unit_variant("Level", 4, "TRACE"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for Level {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
struct LevelIdentifier;
|
||||
|
||||
impl<'de> Visitor<'de> for LevelIdentifier {
|
||||
type Value = Level;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("log level")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
// Case insensitive.
|
||||
FromStr::from_str(s).map_err(|_| Error::unknown_variant(s, &LOG_LEVEL_NAMES[1..]))
|
||||
}
|
||||
|
||||
fn visit_bytes<E>(self, value: &[u8]) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
let variant = str::from_utf8(value)
|
||||
.map_err(|_| Error::invalid_value(Unexpected::Bytes(value), &self))?;
|
||||
|
||||
self.visit_str(variant)
|
||||
}
|
||||
|
||||
fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
let variant = LOG_LEVEL_NAMES[1..]
|
||||
.get(v as usize)
|
||||
.ok_or_else(|| Error::invalid_value(Unexpected::Unsigned(v), &self))?;
|
||||
|
||||
self.visit_str(variant)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> DeserializeSeed<'de> for LevelIdentifier {
|
||||
type Value = Level;
|
||||
|
||||
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_identifier(LevelIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
struct LevelEnum;
|
||||
|
||||
impl<'de> Visitor<'de> for LevelEnum {
|
||||
type Value = Level;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("log level")
|
||||
}
|
||||
|
||||
fn visit_enum<A>(self, value: A) -> Result<Self::Value, A::Error>
|
||||
where
|
||||
A: EnumAccess<'de>,
|
||||
{
|
||||
let (level, variant) = value.variant_seed(LevelIdentifier)?;
|
||||
// Every variant is a unit variant.
|
||||
variant.unit_variant()?;
|
||||
Ok(level)
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_enum("Level", &LOG_LEVEL_NAMES[1..], LevelEnum)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for LevelFilter {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
match *self {
|
||||
LevelFilter::Off => serializer.serialize_unit_variant("LevelFilter", 0, "OFF"),
|
||||
LevelFilter::Error => serializer.serialize_unit_variant("LevelFilter", 1, "ERROR"),
|
||||
LevelFilter::Warn => serializer.serialize_unit_variant("LevelFilter", 2, "WARN"),
|
||||
LevelFilter::Info => serializer.serialize_unit_variant("LevelFilter", 3, "INFO"),
|
||||
LevelFilter::Debug => serializer.serialize_unit_variant("LevelFilter", 4, "DEBUG"),
|
||||
LevelFilter::Trace => serializer.serialize_unit_variant("LevelFilter", 5, "TRACE"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for LevelFilter {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
struct LevelFilterIdentifier;
|
||||
|
||||
impl<'de> Visitor<'de> for LevelFilterIdentifier {
|
||||
type Value = LevelFilter;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("log level filter")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
// Case insensitive.
|
||||
FromStr::from_str(s).map_err(|_| Error::unknown_variant(s, &LOG_LEVEL_NAMES))
|
||||
}
|
||||
|
||||
fn visit_bytes<E>(self, value: &[u8]) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
let variant = str::from_utf8(value)
|
||||
.map_err(|_| Error::invalid_value(Unexpected::Bytes(value), &self))?;
|
||||
|
||||
self.visit_str(variant)
|
||||
}
|
||||
|
||||
fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
let variant = LOG_LEVEL_NAMES
|
||||
.get(v as usize)
|
||||
.ok_or_else(|| Error::invalid_value(Unexpected::Unsigned(v), &self))?;
|
||||
|
||||
self.visit_str(variant)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> DeserializeSeed<'de> for LevelFilterIdentifier {
|
||||
type Value = LevelFilter;
|
||||
|
||||
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_identifier(LevelFilterIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
struct LevelFilterEnum;
|
||||
|
||||
impl<'de> Visitor<'de> for LevelFilterEnum {
|
||||
type Value = LevelFilter;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("log level filter")
|
||||
}
|
||||
|
||||
fn visit_enum<A>(self, value: A) -> Result<Self::Value, A::Error>
|
||||
where
|
||||
A: EnumAccess<'de>,
|
||||
{
|
||||
let (level_filter, variant) = value.variant_seed(LevelFilterIdentifier)?;
|
||||
// Every variant is a unit variant.
|
||||
variant.unit_variant()?;
|
||||
Ok(level_filter)
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_enum("LevelFilter", &LOG_LEVEL_NAMES, LevelFilterEnum)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate serde_test;
|
||||
use self::serde_test::{assert_de_tokens, assert_de_tokens_error, assert_tokens, Token};
|
||||
|
||||
use {Level, LevelFilter};
|
||||
|
||||
fn level_token(variant: &'static str) -> Token {
|
||||
Token::UnitVariant {
|
||||
name: "Level",
|
||||
variant: variant,
|
||||
}
|
||||
}
|
||||
|
||||
fn level_bytes_tokens(variant: &'static [u8]) -> [Token; 3] {
|
||||
[
|
||||
Token::Enum { name: "Level" },
|
||||
Token::Bytes(variant),
|
||||
Token::Unit,
|
||||
]
|
||||
}
|
||||
|
||||
fn level_variant_tokens(variant: u32) -> [Token; 3] {
|
||||
[
|
||||
Token::Enum { name: "Level" },
|
||||
Token::U32(variant),
|
||||
Token::Unit,
|
||||
]
|
||||
}
|
||||
|
||||
fn level_filter_token(variant: &'static str) -> Token {
|
||||
Token::UnitVariant {
|
||||
name: "LevelFilter",
|
||||
variant: variant,
|
||||
}
|
||||
}
|
||||
|
||||
fn level_filter_bytes_tokens(variant: &'static [u8]) -> [Token; 3] {
|
||||
[
|
||||
Token::Enum {
|
||||
name: "LevelFilter",
|
||||
},
|
||||
Token::Bytes(variant),
|
||||
Token::Unit,
|
||||
]
|
||||
}
|
||||
|
||||
fn level_filter_variant_tokens(variant: u32) -> [Token; 3] {
|
||||
[
|
||||
Token::Enum {
|
||||
name: "LevelFilter",
|
||||
},
|
||||
Token::U32(variant),
|
||||
Token::Unit,
|
||||
]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_ser_de() {
|
||||
let cases = [
|
||||
(Level::Error, [level_token("ERROR")]),
|
||||
(Level::Warn, [level_token("WARN")]),
|
||||
(Level::Info, [level_token("INFO")]),
|
||||
(Level::Debug, [level_token("DEBUG")]),
|
||||
(Level::Trace, [level_token("TRACE")]),
|
||||
];
|
||||
|
||||
for &(s, expected) in &cases {
|
||||
assert_tokens(&s, &expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_case_insensitive() {
|
||||
let cases = [
|
||||
(Level::Error, [level_token("error")]),
|
||||
(Level::Warn, [level_token("warn")]),
|
||||
(Level::Info, [level_token("info")]),
|
||||
(Level::Debug, [level_token("debug")]),
|
||||
(Level::Trace, [level_token("trace")]),
|
||||
];
|
||||
|
||||
for &(s, expected) in &cases {
|
||||
assert_de_tokens(&s, &expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_de_bytes() {
|
||||
let cases = [
|
||||
(Level::Error, level_bytes_tokens(b"ERROR")),
|
||||
(Level::Warn, level_bytes_tokens(b"WARN")),
|
||||
(Level::Info, level_bytes_tokens(b"INFO")),
|
||||
(Level::Debug, level_bytes_tokens(b"DEBUG")),
|
||||
(Level::Trace, level_bytes_tokens(b"TRACE")),
|
||||
];
|
||||
|
||||
for &(value, tokens) in &cases {
|
||||
assert_de_tokens(&value, &tokens);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_de_variant_index() {
|
||||
let cases = [
|
||||
(Level::Error, level_variant_tokens(0)),
|
||||
(Level::Warn, level_variant_tokens(1)),
|
||||
(Level::Info, level_variant_tokens(2)),
|
||||
(Level::Debug, level_variant_tokens(3)),
|
||||
(Level::Trace, level_variant_tokens(4)),
|
||||
];
|
||||
|
||||
for &(value, tokens) in &cases {
|
||||
assert_de_tokens(&value, &tokens);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_de_error() {
|
||||
let msg = "unknown variant `errorx`, expected one of \
|
||||
`ERROR`, `WARN`, `INFO`, `DEBUG`, `TRACE`";
|
||||
assert_de_tokens_error::<Level>(&[level_token("errorx")], msg);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_filter_ser_de() {
|
||||
let cases = [
|
||||
(LevelFilter::Off, [level_filter_token("OFF")]),
|
||||
(LevelFilter::Error, [level_filter_token("ERROR")]),
|
||||
(LevelFilter::Warn, [level_filter_token("WARN")]),
|
||||
(LevelFilter::Info, [level_filter_token("INFO")]),
|
||||
(LevelFilter::Debug, [level_filter_token("DEBUG")]),
|
||||
(LevelFilter::Trace, [level_filter_token("TRACE")]),
|
||||
];
|
||||
|
||||
for &(s, expected) in &cases {
|
||||
assert_tokens(&s, &expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_filter_case_insensitive() {
|
||||
let cases = [
|
||||
(LevelFilter::Off, [level_filter_token("off")]),
|
||||
(LevelFilter::Error, [level_filter_token("error")]),
|
||||
(LevelFilter::Warn, [level_filter_token("warn")]),
|
||||
(LevelFilter::Info, [level_filter_token("info")]),
|
||||
(LevelFilter::Debug, [level_filter_token("debug")]),
|
||||
(LevelFilter::Trace, [level_filter_token("trace")]),
|
||||
];
|
||||
|
||||
for &(s, expected) in &cases {
|
||||
assert_de_tokens(&s, &expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_filter_de_bytes() {
|
||||
let cases = [
|
||||
(LevelFilter::Off, level_filter_bytes_tokens(b"OFF")),
|
||||
(LevelFilter::Error, level_filter_bytes_tokens(b"ERROR")),
|
||||
(LevelFilter::Warn, level_filter_bytes_tokens(b"WARN")),
|
||||
(LevelFilter::Info, level_filter_bytes_tokens(b"INFO")),
|
||||
(LevelFilter::Debug, level_filter_bytes_tokens(b"DEBUG")),
|
||||
(LevelFilter::Trace, level_filter_bytes_tokens(b"TRACE")),
|
||||
];
|
||||
|
||||
for &(value, tokens) in &cases {
|
||||
assert_de_tokens(&value, &tokens);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_filter_de_variant_index() {
|
||||
let cases = [
|
||||
(LevelFilter::Off, level_filter_variant_tokens(0)),
|
||||
(LevelFilter::Error, level_filter_variant_tokens(1)),
|
||||
(LevelFilter::Warn, level_filter_variant_tokens(2)),
|
||||
(LevelFilter::Info, level_filter_variant_tokens(3)),
|
||||
(LevelFilter::Debug, level_filter_variant_tokens(4)),
|
||||
(LevelFilter::Trace, level_filter_variant_tokens(5)),
|
||||
];
|
||||
|
||||
for &(value, tokens) in &cases {
|
||||
assert_de_tokens(&value, &tokens);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_filter_de_error() {
|
||||
let msg = "unknown variant `errorx`, expected one of \
|
||||
`OFF`, `ERROR`, `WARN`, `INFO`, `DEBUG`, `TRACE`";
|
||||
assert_de_tokens_error::<LevelFilter>(&[level_filter_token("errorx")], msg);
|
||||
}
|
||||
}
|
1
vendor/log/triagebot.toml
vendored
Normal file
1
vendor/log/triagebot.toml
vendored
Normal file
@ -0,0 +1 @@
|
||||
[assign]
|
Reference in New Issue
Block a user