lazy_static-1.5.0/.cargo_vcs_info.json0000644000000001360000000000100133650ustar { "git": { "sha1": "be7c1c43f264699f956b70ce8e29941bd1e61bde" }, "path_in_vcs": "" }lazy_static-1.5.0/.gitignore000064400000000000000000000000411046102023000141400ustar 00000000000000target doc Cargo.lock .cargo wip lazy_static-1.5.0/Cargo.lock0000644000000172620000000000100113500ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "doc-comment" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "glob" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "indexmap" version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown", ] [[package]] name = "itoa" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "lazy_static" version = "1.5.0" dependencies = [ "doc-comment", "spin", "trybuild", ] [[package]] name = "memchr" version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "proc-macro2" version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] [[package]] name = "ryu" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "serde" version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "serde_json" version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "itoa", "ryu", "serde", ] [[package]] name = "serde_spanned" version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" dependencies = [ "serde", ] [[package]] name = "spin" version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "syn" version = "2.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff8655ed1d86f3af4ee3fd3263786bc14245ad17c4c7e85ba7187fb3ae028c90" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "termcolor" version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] [[package]] name = "toml" version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f49eb2ab21d2f26bd6db7bf383edc527a7ebaee412d17af4d40fdccd442f335" dependencies = [ "serde", "serde_spanned", "toml_datetime", "toml_edit", ] [[package]] name = "toml_datetime" version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" dependencies = [ "serde", ] [[package]] name = "toml_edit" version = "0.22.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f21c7aaf97f1bd9ca9d4f9e73b0a6c74bd5afef56f2bc931943a6e1c37e04e38" dependencies = [ "indexmap", "serde", "serde_spanned", "toml_datetime", "winnow", ] [[package]] name = "trybuild" version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33a5f13f11071020bb12de7a16b925d2d58636175c20c11dc5f96cb64bb6c9b3" dependencies = [ "glob", "serde", "serde_derive", "serde_json", "termcolor", "toml", ] [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "winapi-util" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ "windows-sys", ] [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" [[package]] name = "windows_i686_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" version = "0.6.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59b5e5f6c299a3c7890b876a2a587f3115162487e704907d9b6cd29473052ba1" dependencies = [ "memchr", ] lazy_static-1.5.0/Cargo.toml0000644000000022430000000000100113640ustar # 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] name = "lazy_static" version = "1.5.0" authors = ["Marvin Löbel "] exclude = [".github"] description = "A macro for declaring lazily evaluated statics in Rust." documentation = "https://docs.rs/lazy_static" readme = "README.md" keywords = [ "macro", "lazy", "static", ] categories = [ "no-std", "rust-patterns", "memory-management", ] license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang-nursery/lazy-static.rs" [dependencies.spin] version = "0.9.8" features = ["once"] optional = true default-features = false [dev-dependencies.doc-comment] version = "0.3.1" [dev-dependencies.trybuild] version = "1" [features] spin_no_std = ["spin"] lazy_static-1.5.0/Cargo.toml.orig000064400000000000000000000013141046102023000150430ustar 00000000000000[package] name = "lazy_static" # NB: When modifying, also modify html_root_url in lib.rs version = "1.5.0" authors = ["Marvin Löbel "] license = "MIT OR Apache-2.0" description = "A macro for declaring lazily evaluated statics in Rust." readme = "README.md" documentation = "https://docs.rs/lazy_static" repository = "https://github.com/rust-lang-nursery/lazy-static.rs" keywords = ["macro", "lazy", "static"] categories = [ "no-std", "rust-patterns", "memory-management" ] exclude = [".github"] [dependencies.spin] version = "0.9.8" default-features = false features = ["once"] optional = true [features] spin_no_std = ["spin"] [dev-dependencies] doc-comment = "0.3.1" trybuild = "1" lazy_static-1.5.0/LICENSE-APACHE000064400000000000000000000251371046102023000141110ustar 00000000000000 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. lazy_static-1.5.0/LICENSE-MIT000064400000000000000000000020571046102023000136150ustar 00000000000000Copyright (c) 2010 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. lazy_static-1.5.0/README.md000064400000000000000000000067251046102023000134460ustar 00000000000000lazy-static.rs ============== A macro for declaring lazily evaluated statics in Rust. Using this macro, it is possible to have `static`s that require code to be executed at runtime in order to be initialized. This includes anything requiring heap allocations, like vectors or hash maps, as well as anything that requires non-const function calls to be computed. [![Rust](https://github.com/rust-lang-nursery/lazy-static.rs/actions/workflows/rust.yml/badge.svg)](https://github.com/rust-lang-nursery/lazy-static.rs/actions/workflows/rust.yml) [![Latest version](https://img.shields.io/crates/v/lazy_static.svg)](https://crates.io/crates/lazy_static) [![Documentation](https://docs.rs/lazy_static/badge.svg)](https://docs.rs/lazy_static) [![License](https://img.shields.io/crates/l/lazy_static.svg)](https://github.com/rust-lang-nursery/lazy-static.rs#license) ## Minimum supported `rustc` `1.40.0+` This version is explicitly tested in CI and may only be bumped in new minor versions. Any changes to the supported minimum version will be called out in the release notes. # Getting Started [lazy-static.rs is available on crates.io](https://crates.io/crates/lazy_static). It is recommended to look there for the newest released version, as well as links to the newest builds of the docs. At the point of the last update of this README, the latest published version could be used like this: Add the following dependency to your Cargo manifest... ```toml [dependencies] lazy_static = "1.5.0" ``` ...and see the [docs](https://docs.rs/lazy_static) for how to use it. # Example ```rust use lazy_static::lazy_static; use std::collections::HashMap; lazy_static! { static ref HASHMAP: HashMap = { let mut m = HashMap::new(); m.insert(0, "foo"); m.insert(1, "bar"); m.insert(2, "baz"); m }; } fn main() { // First access to `HASHMAP` initializes it println!("The entry for `0` is \"{}\".", HASHMAP.get(&0).unwrap()); // Any further access to `HASHMAP` just returns the computed value println!("The entry for `1` is \"{}\".", HASHMAP.get(&1).unwrap()); } ``` # Standard library It is now possible to easily replicate this crate's functionality in Rust's standard library with [`std::sync::OnceLock`](https://doc.rust-lang.org/std/sync/struct.OnceLock.html). The example above could be also be written as: ```rust use std::collections::HashMap; use std::sync::OnceLock; fn hashmap() -> &'static HashMap { static HASHMAP: OnceLock> = OnceLock::new(); HASHMAP.get_or_init(|| { let mut m = HashMap::new(); m.insert(0, "foo"); m.insert(1, "bar"); m.insert(2, "baz"); m }) } fn main() { // First access to `HASHMAP` initializes it println!("The entry for `0` is \"{}\".", hashmap().get(&0).unwrap()); // Any further access to `HASHMAP` just returns the computed value println!("The entry for `1` is \"{}\".", hashmap().get(&1).unwrap()); } ``` ## License Licensed under either of * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0) * MIT license ([LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. lazy_static-1.5.0/examples/mutex_map.rs000064400000000000000000000011361046102023000163410ustar 00000000000000//! This example shows how to wrap a data structure in a mutex to achieve safe mutability. extern crate lazy_static; use lazy_static::lazy_static; use std::collections::HashMap; use std::sync::Mutex; lazy_static! { static ref MUTEX_MAP: Mutex> = { let mut m = HashMap::new(); m.insert(0, "foo"); m.insert(1, "bar"); m.insert(2, "baz"); Mutex::new(m) }; } fn main() { MUTEX_MAP.lock().unwrap().insert(0, "boo"); println!( "The entry for `0` is \"{}\".", MUTEX_MAP.lock().unwrap().get(&0).unwrap() ); } lazy_static-1.5.0/src/core_lazy.rs000064400000000000000000000014761046102023000153110ustar 00000000000000// Copyright 2016 lazy-static.rs Developers // // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be // copied, modified, or distributed except according to those terms. extern crate spin; use self::spin::Once; pub struct Lazy(Once); impl Lazy { pub const INIT: Self = Lazy(Once::INIT); #[inline(always)] pub fn get(&'static self, builder: F) -> &T where F: FnOnce() -> T, { self.0.call_once(builder) } } #[macro_export] #[doc(hidden)] macro_rules! __lazy_static_create { ($NAME:ident, $T:ty) => { static $NAME: $crate::lazy::Lazy<$T> = $crate::lazy::Lazy::INIT; }; } lazy_static-1.5.0/src/inline_lazy.rs000064400000000000000000000025411046102023000156310ustar 00000000000000// Copyright 2016 lazy-static.rs Developers // // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be // copied, modified, or distributed except according to those terms. extern crate core; extern crate std; use self::std::cell::Cell; use self::std::mem::MaybeUninit; use self::std::prelude::v1::*; use self::std::sync::Once; #[allow(deprecated)] pub use self::std::sync::ONCE_INIT; #[allow(dead_code)] // Used in macros pub struct Lazy(Cell>, Once); impl Lazy { #[allow(deprecated)] pub const INIT: Self = Lazy(Cell::new(MaybeUninit::uninit()), ONCE_INIT); #[inline(always)] pub fn get(&'static self, f: F) -> &T where F: FnOnce() -> T, { self.1.call_once(|| { self.0.set(MaybeUninit::new(f())); }); // `self.0` is guaranteed to be initialized by this point // The `Once` will catch and propagate panics unsafe { &*(*self.0.as_ptr()).as_ptr() } } } unsafe impl Sync for Lazy {} #[macro_export] #[doc(hidden)] macro_rules! __lazy_static_create { ($NAME:ident, $T:ty) => { static $NAME: $crate::lazy::Lazy<$T> = $crate::lazy::Lazy::INIT; }; } lazy_static-1.5.0/src/lib.rs000064400000000000000000000142751046102023000140710ustar 00000000000000// Copyright 2016 lazy-static.rs Developers // // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be // copied, modified, or distributed except according to those terms. /*! A macro for declaring lazily evaluated statics. Using this macro, it is possible to have `static`s that require code to be executed at runtime in order to be initialized. This includes anything requiring heap allocations, like vectors or hash maps, as well as anything that requires function calls to be computed. # Syntax ```ignore lazy_static! { [pub] static ref NAME_1: TYPE_1 = EXPR_1; [pub] static ref NAME_2: TYPE_2 = EXPR_2; ... [pub] static ref NAME_N: TYPE_N = EXPR_N; } ``` Attributes (including doc comments) are supported as well: ```rust use lazy_static::lazy_static; # fn main() { lazy_static! { /// This is an example for using doc comment attributes static ref EXAMPLE: u8 = 42; } # } ``` # Semantics For a given `static ref NAME: TYPE = EXPR;`, the macro generates a unique type that implements `Deref` and stores it in a static with name `NAME`. (Attributes end up attaching to this type.) On first deref, `EXPR` gets evaluated and stored internally, such that all further derefs can return a reference to the same object. Note that this can lead to deadlocks if you have multiple lazy statics that depend on each other in their initialization. Apart from the lazy initialization, the resulting "static ref" variables have generally the same properties as regular "static" variables: - Any type in them needs to fulfill the `Sync` trait. - If the type has a destructor, then it will not run when the process exits. # Example Using the macro: ```rust use lazy_static::lazy_static; use std::collections::HashMap; lazy_static! { static ref HASHMAP: HashMap = { let mut m = HashMap::new(); m.insert(0, "foo"); m.insert(1, "bar"); m.insert(2, "baz"); m }; static ref COUNT: usize = HASHMAP.len(); static ref NUMBER: u32 = times_two(21); } fn times_two(n: u32) -> u32 { n * 2 } fn main() { println!("The map has {} entries.", *COUNT); println!("The entry for `0` is \"{}\".", HASHMAP.get(&0).unwrap()); println!("A expensive calculation on a static results in: {}.", *NUMBER); } ``` # Implementation details The `Deref` implementation uses a hidden static variable that is guarded by an atomic check on each access. # Cargo features This crate provides one cargo feature: - `spin_no_std`: This allows using this crate in a no-std environment, by depending on the standalone `spin` crate. */ #![doc(html_root_url = "https://docs.rs/lazy_static/1.5.0")] #![no_std] #[cfg(doctest)] #[macro_use] extern crate doc_comment; #[cfg(doctest)] doctest!("../README.md"); #[cfg_attr(feature = "spin_no_std", path = "core_lazy.rs")] #[cfg_attr(not(feature = "spin_no_std"), path = "inline_lazy.rs")] #[doc(hidden)] pub mod lazy; #[doc(hidden)] pub use core::ops::Deref as __Deref; #[macro_export(local_inner_macros)] #[doc(hidden)] macro_rules! __lazy_static_internal { // optional visibility restrictions are wrapped in `()` to allow for // explicitly passing otherwise implicit information about private items ($(#[$attr:meta])* ($($vis:tt)*) static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => { __lazy_static_internal!(@MAKE TY, $(#[$attr])*, ($($vis)*), $N); __lazy_static_internal!(@TAIL, $N : $T = $e); lazy_static!($($t)*); }; (@TAIL, $N:ident : $T:ty = $e:expr) => { impl $crate::__Deref for $N { type Target = $T; fn deref(&self) -> &$T { #[inline(always)] fn __static_ref_initialize() -> $T { $e } #[inline(always)] fn __stability() -> &'static $T { __lazy_static_create!(LAZY, $T); LAZY.get(__static_ref_initialize) } __stability() } } impl $crate::LazyStatic for $N { fn initialize(lazy: &Self) { let _ = &**lazy; } } }; // `vis` is wrapped in `()` to prevent parsing ambiguity (@MAKE TY, $(#[$attr:meta])*, ($($vis:tt)*), $N:ident) => { #[allow(missing_copy_implementations)] #[allow(non_camel_case_types)] #[allow(dead_code)] $(#[$attr])* $($vis)* struct $N {__private_field: ()} #[doc(hidden)] #[allow(non_upper_case_globals)] $($vis)* static $N: $N = $N {__private_field: ()}; }; () => () } #[macro_export(local_inner_macros)] macro_rules! lazy_static { ($(#[$attr:meta])* static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => { // use `()` to explicitly forward the information about private items __lazy_static_internal!($(#[$attr])* () static ref $N : $T = $e; $($t)*); }; ($(#[$attr:meta])* pub static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => { __lazy_static_internal!($(#[$attr])* (pub) static ref $N : $T = $e; $($t)*); }; ($(#[$attr:meta])* pub ($($vis:tt)+) static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => { __lazy_static_internal!($(#[$attr])* (pub ($($vis)+)) static ref $N : $T = $e; $($t)*); }; () => () } /// Support trait for enabling a few common operation on lazy static values. /// /// This is implemented by each defined lazy static, and /// used by the free functions in this crate. pub trait LazyStatic { #[doc(hidden)] fn initialize(lazy: &Self); } /// Takes a shared reference to a lazy static and initializes /// it if it has not been already. /// /// This can be used to control the initialization point of a lazy static. /// /// Example: /// /// ```rust /// use lazy_static::lazy_static; /// /// lazy_static! { /// static ref BUFFER: Vec = (0..255).collect(); /// } /// /// fn main() { /// lazy_static::initialize(&BUFFER); /// /// // ... /// work_with_initialized_data(&BUFFER); /// } /// # fn work_with_initialized_data(_: &[u8]) {} /// ``` pub fn initialize(lazy: &T) { LazyStatic::initialize(lazy); } lazy_static-1.5.0/tests/compile_fail/incorrect_visibility_restriction.rs000064400000000000000000000001651046102023000251760ustar 00000000000000#[macro_use] extern crate lazy_static; lazy_static! { pub(nonsense) static ref WRONG: () = (); } fn main() { } lazy_static-1.5.0/tests/compile_fail/incorrect_visibility_restriction.stderr000064400000000000000000000010041046102023000260460ustar 00000000000000error[E0704]: incorrect visibility restriction --> tests/compile_fail/incorrect_visibility_restriction.rs:5:9 | 5 | pub(nonsense) static ref WRONG: () = (); | ^^^^^^^^ help: make this visible only to module `nonsense` with `in`: `in nonsense` | = help: some possible visibility restrictions are: `pub(crate)`: visible only on the current crate `pub(super)`: visible only in the current module's parent `pub(in path::to::module)`: visible only on the specified path lazy_static-1.5.0/tests/compile_fail/static_is_private.rs000064400000000000000000000003331046102023000220230ustar 00000000000000#[macro_use] extern crate lazy_static; mod outer { pub mod inner { lazy_static! { pub(in outer) static ref FOO: () = (); } } } fn main() { assert_eq!(*outer::inner::FOO, ()); } lazy_static-1.5.0/tests/compile_fail/static_is_private.stderr000064400000000000000000000010321046102023000226770ustar 00000000000000error[E0603]: static `FOO` is private --> tests/compile_fail/static_is_private.rs:13:31 | 13 | assert_eq!(*outer::inner::FOO, ()); | ^^^ private static | note: the static `FOO` is defined here --> tests/compile_fail/static_is_private.rs:6:9 | 6 | / lazy_static! { 7 | | pub(in outer) static ref FOO: () = (); 8 | | } | |_________^ = note: this error originates in the macro `lazy_static` (in Nightly builds, run with -Z macro-backtrace for more info) lazy_static-1.5.0/tests/compile_fail/static_is_sized.rs000064400000000000000000000001611046102023000214660ustar 00000000000000#[macro_use] extern crate lazy_static; lazy_static! { pub static ref FOO: str = panic!(); } fn main() { } lazy_static-1.5.0/tests/compile_fail/static_is_sized.stderr000064400000000000000000000057651046102023000223640ustar 00000000000000error[E0277]: the size for values of type `str` cannot be known at compilation time --> tests/compile_fail/static_is_sized.rs:4:1 | 4 | / lazy_static! { 5 | | pub static ref FOO: str = panic!(); 6 | | } | |_^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `str` note: required by an implicit `Sized` bound in `Lazy` --> src/inline_lazy.rs | | pub struct Lazy(Cell>, Once); | ^ required by the implicit `Sized` requirement on this type parameter in `Lazy` = note: this error originates in the macro `__lazy_static_create` which comes from the expansion of the macro `lazy_static` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the size for values of type `str` cannot be known at compilation time --> tests/compile_fail/static_is_sized.rs:4:1 | 4 | / lazy_static! { 5 | | pub static ref FOO: str = panic!(); 6 | | } | |_^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `str` note: required by an implicit `Sized` bound in `Lazy` --> src/inline_lazy.rs | | pub struct Lazy(Cell>, Once); | ^ required by the implicit `Sized` requirement on this type parameter in `Lazy` = note: this error originates in the macro `__lazy_static_create` which comes from the expansion of the macro `lazy_static` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the size for values of type `str` cannot be known at compilation time --> tests/compile_fail/static_is_sized.rs:5:25 | 5 | pub static ref FOO: str = panic!(); | ^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `str` = note: the return type of a function must have a statically known size error[E0599]: the method `get` exists for struct `Lazy`, but its trait bounds were not satisfied --> tests/compile_fail/static_is_sized.rs:4:1 | 4 | / lazy_static! { 5 | | pub static ref FOO: str = panic!(); 6 | | } | |_^ method cannot be called on `Lazy` due to unsatisfied trait bounds | = note: the following trait bounds were not satisfied: `str: Sized` = note: this error originates in the macro `__lazy_static_internal` which comes from the expansion of the macro `lazy_static` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the size for values of type `str` cannot be known at compilation time --> tests/compile_fail/static_is_sized.rs:4:1 | 4 | / lazy_static! { 5 | | pub static ref FOO: str = panic!(); 6 | | } | |_^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `str` = note: the return type of a function must have a statically known size = note: this error originates in the macro `__lazy_static_internal` which comes from the expansion of the macro `lazy_static` (in Nightly builds, run with -Z macro-backtrace for more info) lazy_static-1.5.0/tests/no_std.rs000064400000000000000000000004201046102023000151470ustar 00000000000000#![cfg(feature = "spin_no_std")] #![no_std] #[macro_use] extern crate lazy_static; lazy_static! { /// Documentation! pub static ref NUMBER: u32 = times_two(3); } fn times_two(n: u32) -> u32 { n * 2 } #[test] fn test_basic() { assert_eq!(*NUMBER, 6); } lazy_static-1.5.0/tests/test.rs000064400000000000000000000100011046102023000146340ustar 00000000000000#![deny(warnings)] #[macro_use] extern crate lazy_static; use std::collections::HashMap; lazy_static! { /// Documentation! pub static ref NUMBER: u32 = times_two(3); static ref ARRAY_BOXES: [Box; 3] = [Box::new(1), Box::new(2), Box::new(3)]; /// More documentation! #[allow(unused_variables)] #[derive(Copy, Clone, Debug)] pub static ref STRING: String = "hello".to_string(); static ref HASHMAP: HashMap = { let mut m = HashMap::new(); m.insert(0, "abc"); m.insert(1, "def"); m.insert(2, "ghi"); m }; // This should not compile if the unsafe is removed. static ref UNSAFE: u32 = unsafe { std::mem::transmute::(-1) }; } lazy_static! { static ref S1: &'static str = "a"; static ref S2: &'static str = "b"; } lazy_static! { static ref S3: String = [*S1, *S2].join(""); } lazy_static! { #[allow(non_upper_case_globals)] pub static ref string: String = "hello".to_string(); } #[test] fn s3() { assert_eq!(&*S3, "ab"); } fn times_two(n: u32) -> u32 { n * 2 } #[test] fn test_basic() { assert_eq!(&**STRING, "hello"); assert_eq!(*NUMBER, 6); assert!(HASHMAP.get(&1).is_some()); assert!(HASHMAP.get(&3).is_none()); assert_eq!(&*ARRAY_BOXES, &[Box::new(1), Box::new(2), Box::new(3)]); assert_eq!(*UNSAFE, std::u32::MAX); } #[test] fn test_repeat() { assert_eq!(*NUMBER, 6); assert_eq!(*NUMBER, 6); assert_eq!(*NUMBER, 6); } #[test] fn test_meta() { // this would not compile if STRING were not marked #[derive(Copy, Clone)] let copy_of_string = STRING; // just to make sure it was copied assert!(&STRING as *const _ != ©_of_string as *const _); // this would not compile if STRING were not marked #[derive(Debug)] assert_eq!( format!("{:?}", STRING), "STRING { __private_field: () }".to_string() ); } mod visibility { lazy_static! { pub static ref FOO: Box = Box::new(0); static ref BAR: Box = Box::new(98); } pub mod inner { lazy_static! { pub(in visibility) static ref BAZ: Box = Box::new(42); pub(crate) static ref BAG: Box = Box::new(37); } } #[test] fn sub_test() { assert_eq!(**FOO, 0); assert_eq!(**BAR, 98); assert_eq!(**inner::BAZ, 42); assert_eq!(**inner::BAG, 37); } } #[test] fn test_visibility() { assert_eq!(*visibility::FOO, Box::new(0)); assert_eq!(*visibility::inner::BAG, Box::new(37)); } // This should not cause a warning about a missing Copy implementation lazy_static! { pub static ref VAR: i32 = 0; } #[derive(Copy, Clone, Debug, PartialEq)] struct X; struct Once(X); const ONCE_INIT: Once = Once(X); static DATA: X = X; static ONCE: X = X; fn require_sync() -> X { X } fn transmute() -> X { X } fn __static_ref_initialize() -> X { X } fn test(_: Vec) -> X { X } // All these names should not be shadowed lazy_static! { static ref ITEM_NAME_TEST: X = { test(vec![X, Once(X).0, ONCE_INIT.0, DATA, ONCE, require_sync(), transmute(), // Except this, which will sadly be shadowed by internals: // __static_ref_initialize() ]) }; } #[test] fn item_name_shadowing() { assert_eq!(*ITEM_NAME_TEST, X); } use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering::SeqCst; #[allow(deprecated)] use std::sync::atomic::ATOMIC_BOOL_INIT; #[allow(deprecated)] static PRE_INIT_FLAG: AtomicBool = ATOMIC_BOOL_INIT; lazy_static! { static ref PRE_INIT: () = { PRE_INIT_FLAG.store(true, SeqCst); () }; } #[test] fn pre_init() { assert_eq!(PRE_INIT_FLAG.load(SeqCst), false); lazy_static::initialize(&PRE_INIT); assert_eq!(PRE_INIT_FLAG.load(SeqCst), true); } lazy_static! { static ref LIFETIME_NAME: for<'a> fn(&'a u8) = { fn f(_: &u8) {} f }; } #[test] fn lifetime_name() { let _ = LIFETIME_NAME; } lazy_static-1.5.0/tests/ui.rs000064400000000000000000000001751046102023000143050ustar 00000000000000#[test] #[cfg(not(miri))] fn ui() { let t = trybuild::TestCases::new(); t.compile_fail("tests/compile_fail/*.rs"); }