| 1 | //! This module provides a mechanism for creating and managing composite keys |
| 2 | //! used in anchor lookups. It allows for efficient lookups without the need |
| 3 | //! to construct data structures with owned values. |
| 4 | //! |
| 5 | //! The key components are: |
| 6 | //! - `AnchorKey`: An owned version of the composite key. |
| 7 | //! - `AnchorKeyRef`: A borrowed version of the composite key. |
| 8 | //! - `BorrowDyn`: A trait that allows for dynamic borrowing of key components. |
| 9 | //! |
| 10 | //! This design enables the use of borrowed data in hash map lookups while |
| 11 | //! still storing owned data. |
| 12 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 13 | borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#, |
| 14 | hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::{Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#, Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#}, |
| 15 | syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#, |
| 16 | }; |
| 17 | |
| 18 | use fluent_urirust-analyzer cargo fluent-uri 0.4.1 crate/::Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#; |
| 19 | |
| 20 | use superrust-analyzer cargo referencing 0.37.4 anchors/::AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName#; |
| 21 | |
| 22 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 23 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) struct AnchorKeyrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey# { |
| 24 | urirust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey#uri.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, |
| 25 | namerust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey#name.: AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName#, |
| 26 | } |
| 27 | |
| 28 | impl AnchorKeyrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey# { |
| 29 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn newrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[AnchorKey]new().(uri: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, name: AnchorNamerust-analyzer cargo referencing 0.37.4 anchors/AnchorName#) -> Selfrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[AnchorKey] { |
| 30 | Selfrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[AnchorKey] { urirust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey#uri., namerust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey#name. } |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 35 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) struct AnchorKeyRefrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKeyRef#<'a> { |
| 36 | urirust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKeyRef#uri.: &'a Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 37 | namerust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKeyRef#name.: &'a str, |
| 38 | } |
| 39 | |
| 40 | impl<'a> AnchorKeyRefrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKeyRef#<'a> { |
| 41 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn newrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[`AnchorKeyRef<'a>`]new().(uri: &'a Urirust-analyzer cargo fluent-uri 0.4.1 imp/Uri#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, name: &'a str) -> Selfrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[`AnchorKeyRef<'a>`] { |
| 42 | AnchorKeyRefrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKeyRef# { urirust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKeyRef#uri., namerust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKeyRef#name. } |
| 43 | } |
| 44 | |
| 45 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) fn borrow_dynrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[`AnchorKeyRef<'a>`]borrow_dyn().(&self) -> &dyn BorrowDynrust-analyzer cargo referencing 0.37.4 anchors/keys/BorrowDyn# { |
| 46 | self as &dyn BorrowDynrust-analyzer cargo referencing 0.37.4 anchors/keys/BorrowDyn# |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | pub(craterust-analyzer cargo referencing 0.37.4 crate/) trait BorrowDynrust-analyzer cargo referencing 0.37.4 anchors/keys/BorrowDyn# { |
| 51 | fn borrowed_keyrust-analyzer cargo referencing 0.37.4 anchors/keys/BorrowDyn#borrowed_key().(&self) -> AnchorKeyRefrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKeyRef#<'_>; |
| 52 | } |
| 53 | |
| 54 | impl BorrowDynrust-analyzer cargo referencing 0.37.4 anchors/keys/BorrowDyn# for AnchorKeyrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey# { |
| 55 | fn borrowed_keyrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[AnchorKey][BorrowDyn]borrowed_key().(&self) -> AnchorKeyRefrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKeyRef#<'_> { |
| 56 | AnchorKeyRefrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKeyRef#::newrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[`AnchorKeyRef<'a>`]new().(&self.urirust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey#uri., self.namerust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey#name..as_strrust-analyzer cargo referencing 0.37.4 anchors/impl#[AnchorName]as_str().()) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | impl BorrowDynrust-analyzer cargo referencing 0.37.4 anchors/keys/BorrowDyn# for AnchorKeyRefrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKeyRef#<'_> { |
| 61 | fn borrowed_keyrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[`AnchorKeyRef<'_>`][BorrowDyn]borrowed_key().(&self) -> AnchorKeyRefrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKeyRef#<'_> { |
| 62 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | impl<'a> Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<dyn BorrowDynrust-analyzer cargo referencing 0.37.4 anchors/keys/BorrowDyn# + 'a> for AnchorKeyrust-analyzer cargo referencing 0.37.4 anchors/keys/AnchorKey# { |
| 67 | fn borrowrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[AnchorKey][`Borrow<dyn BorrowDyn + 'a>`]borrow().(&self) -> &(dyn BorrowDynrust-analyzer cargo referencing 0.37.4 anchors/keys/BorrowDyn# + 'a) { |
| 68 | self |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | impl Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# for dyn BorrowDynrust-analyzer cargo referencing 0.37.4 anchors/keys/BorrowDyn# + '_ {} |
| 73 | |
| 74 | impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# for dyn BorrowDynrust-analyzer cargo referencing 0.37.4 anchors/keys/BorrowDyn# + '_ { |
| 75 | fn eqrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[`dyn BorrowDyn`][`PartialEq<Self>`]eq().(&self, other: &dyn BorrowDynrust-analyzer cargo referencing 0.37.4 anchors/keys/BorrowDyn#) -> bool { |
| 76 | self.borrowed_keyrust-analyzer cargo referencing 0.37.4 anchors/keys/BorrowDyn#borrowed_key().().eqrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[`AnchorKeyRef<'a>`][`PartialEq<Self>`]eq().(&other.borrowed_keyrust-analyzer cargo referencing 0.37.4 anchors/keys/BorrowDyn#borrowed_key().()) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | impl Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# for dyn BorrowDynrust-analyzer cargo referencing 0.37.4 anchors/keys/BorrowDyn# + '_ { |
| 81 | fn hashrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[`dyn BorrowDyn`][Hash]hash().<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) { |
| 82 | self.borrowed_keyrust-analyzer cargo referencing 0.37.4 anchors/keys/BorrowDyn#borrowed_key().().hashrust-analyzer cargo referencing 0.37.4 anchors/keys/impl#[`AnchorKeyRef<'a>`][Hash]hash().(state); |
| 83 | } |
| 84 | } |