| 1 | #![deny(missing_docs)] |
| 2 | //! A library for parsing and manipulating APT source files that |
| 3 | //! use the DEB822 format to hold package repositories specifications. |
| 4 | //! |
| 5 | //! <div class="warning"> |
| 6 | //! |
| 7 | //! Currently only lossy _serialization_ is implemented, lossless support |
| 8 | //! retaining file sequence and comments would come at later date. |
| 9 | //! |
| 10 | //! </div> |
| 11 | //! |
| 12 | //! # Examples |
| 13 | //! |
| 14 | //! ```rust |
| 15 | //! |
| 16 | //! use apt_sources::Repositories; |
| 17 | //! use std::path::Path; |
| 18 | //! |
| 19 | //! let text = r#"Types: deb |
| 20 | //! URIs: http://ports.ubuntu.com/ |
| 21 | //! Suites: noble |
| 22 | //! Components: stable |
| 23 | //! Architectures: arm64 |
| 24 | //! Signed-By: |
| 25 | //! -----BEGIN PGP PUBLIC KEY BLOCK----- |
| 26 | //! . |
| 27 | //! mDMEY865UxYJKwYBBAHaRw8BAQdAd7Z0srwuhlB6JKFkcf4HU4SSS/xcRfwEQWzr |
| 28 | //! crf6AEq0SURlYmlhbiBTdGFibGUgUmVsZWFzZSBLZXkgKDEyL2Jvb2t3b3JtKSA8 |
| 29 | //! ZGViaWFuLXJlbGVhc2VAbGlzdHMuZGViaWFuLm9yZz6IlgQTFggAPhYhBE1k/sEZ |
| 30 | //! wgKQZ9bnkfjSWFuHg9SBBQJjzrlTAhsDBQkPCZwABQsJCAcCBhUKCQgLAgQWAgMB |
| 31 | //! Ah4BAheAAAoJEPjSWFuHg9SBSgwBAP9qpeO5z1s5m4D4z3TcqDo1wez6DNya27QW |
| 32 | //! WoG/4oBsAQCEN8Z00DXagPHbwrvsY2t9BCsT+PgnSn9biobwX7bDDg== |
| 33 | //! =5NZE |
| 34 | //! -----END PGP PUBLIC KEY BLOCK-----"#; |
| 35 | //! |
| 36 | //! let r = text.parse::<Repositories>().unwrap(); |
| 37 | //! let suites = r[0].suites(); |
| 38 | //! assert_eq!(suites[0], "noble"); |
| 39 | //! ``` |
| 40 | //! |
| 41 | // TODO: Not supported yet: |
| 42 | // See the ``lossless`` module (behind the ``lossless`` feature) for a more forgiving parser that |
| 43 | // allows partial parsing, parsing files with errors and unknown fields and editing while |
| 44 | // preserving formatting. |
| 45 | |
| 46 | use deb822_fastrust-analyzer cargo deb822-fast 0.2.3 crate/::{FromDeb822rust-analyzer cargo deb822-derive 0.3.1 FromDeb822:, FromDeb822Paragraphrust-analyzer cargo deb822-fast 0.2.3 convert/FromDeb822Paragraph#, ToDeb822rust-analyzer cargo deb822-derive 0.3.1 ToDeb822:, ToDeb822Paragraphrust-analyzer cargo deb822-fast 0.2.3 convert/ToDeb822Paragraph#}; |
| 47 | use errorrust-analyzer cargo apt-sources 0.3.0 error/::{LoadErrorrust-analyzer cargo apt-sources 0.3.0 error/LoadError#, RepositoryErrorrust-analyzer cargo apt-sources 0.3.0 error/RepositoryError#}; |
| 48 | use itertoolsrust-analyzer cargo itertools 0.14.0 crate/::Itertoolsrust-analyzer cargo itertools 0.14.0 Itertools#; |
| 49 | #[cfg(feature = "legacy")] |
| 50 | use legacyrust-analyzer cargo apt-sources 0.3.0 legacy/::LegacyRepositoriesrust-analyzer cargo apt-sources 0.3.0 legacy/LegacyRepositories#; |
| 51 | use signaturerust-analyzer cargo apt-sources 0.3.0 signature/::Signaturerust-analyzer cargo apt-sources 0.3.0 signature/Signature#; |
| 52 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#; |
| 53 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#; |
| 54 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#, opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#, strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#}; |
| 55 | use urlrust-analyzer cargo url 2.5.8 crate/::Urlrust-analyzer cargo url 2.5.8 Url#; |
| 56 | |
| 57 | /// Distribution detection and utilities |
| 58 | pub mod distributionrust-analyzer cargo apt-sources 0.3.0 distribution/; |
| 59 | pub mod errorrust-analyzer cargo apt-sources 0.3.0 error/; |
| 60 | /// Key management utilities for GPG keys |
| 61 | #[cfg(feature = "key-management")] |
| 62 | pub mod key_managementrust-analyzer cargo apt-sources 0.3.0 key_management/; |
| 63 | #[cfg(feature = "key-management")] |
| 64 | pub mod keyserverrust-analyzer cargo apt-sources 0.3.0 keyserver/; |
| 65 | /// Launchpad PPA (Personal Package Archive) integration |
| 66 | #[cfg(feature = "launchpad")] |
| 67 | pub mod launchpadrust-analyzer cargo apt-sources 0.3.0 launchpad/; |
| 68 | #[cfg(feature = "legacy")] |
| 69 | pub mod legacyrust-analyzer cargo apt-sources 0.3.0 legacy/; |
| 70 | pub mod signaturerust-analyzer cargo apt-sources 0.3.0 signature/; |
| 71 | /// Module for managing APT source lists |
| 72 | pub mod sources_managerrust-analyzer cargo apt-sources 0.3.0 sources_manager/; |
| 73 | /// General utilities |
| 74 | pub mod utilsrust-analyzer cargo apt-sources 0.3.0 utils/; |
| 75 | |
| 76 | /// A representation of the repository type, by role of packages it can provide, either `Binary` |
| 77 | /// (indicated by `deb`) or `Source` (indicated by `deb-src`). |
| 78 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(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:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, 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:)] |
| 79 | pub enum RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType# { |
| 80 | /// Repository with binary packages, indicated as `deb` |
| 81 | Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#, |
| 82 | /// Repository with source packages, indicated as `deb-src` |
| 83 | Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#, |
| 84 | } |
| 85 | |
| 86 | impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType# { |
| 87 | type Errrust-analyzer cargo apt-sources 0.3.0 impl#[RepositoryType][FromStr]Err# = RepositoryErrorrust-analyzer cargo apt-sources 0.3.0 error/RepositoryError#; |
| 88 | |
| 89 | fn from_strrust-analyzer cargo apt-sources 0.3.0 impl#[RepositoryType][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo apt-sources 0.3.0 impl#[RepositoryType][FromStr], Selfrust-analyzer cargo apt-sources 0.3.0 impl#[RepositoryType][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> { |
| 90 | match s { |
| 91 | "deb" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#), |
| 92 | "deb-src" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#), |
| 93 | _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RepositoryErrorrust-analyzer cargo apt-sources 0.3.0 error/RepositoryError#::InvalidTyperust-analyzer cargo apt-sources 0.3.0 error/RepositoryError#InvalidType#), |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#> for Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 99 | fn fromrust-analyzer cargo apt-sources 0.3.0 impl#[String][`From<&RepositoryType>`]from().(value: &RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#) -> Selfrust-analyzer cargo apt-sources 0.3.0 impl#[String][`From<&RepositoryType>`] { |
| 100 | match value { |
| 101 | RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary# => "deb".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 102 | RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source# => "deb-src".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType# { |
| 108 | fn fmtrust-analyzer cargo apt-sources 0.3.0 impl#[RepositoryType][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 109 | let s = match self { |
| 110 | RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary# => "deb", |
| 111 | RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source# => "deb-src", |
| 112 | }; |
| 113 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{s}") |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | #[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:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 118 | /// Enumeration for fields like `By-Hash` which have third value of `force` |
| 119 | pub enum YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce# { |
| 120 | /// True |
| 121 | Yesrust-analyzer cargo apt-sources 0.3.0 YesNoForce#Yes#, |
| 122 | /// False |
| 123 | Norust-analyzer cargo apt-sources 0.3.0 YesNoForce#No#, |
| 124 | /// Forced |
| 125 | Forcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#Force#, |
| 126 | } |
| 127 | |
| 128 | impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce# { |
| 129 | type Errrust-analyzer cargo apt-sources 0.3.0 impl#[YesNoForce][FromStr]Err# = RepositoryErrorrust-analyzer cargo apt-sources 0.3.0 error/RepositoryError#; |
| 130 | |
| 131 | fn from_strrust-analyzer cargo apt-sources 0.3.0 impl#[YesNoForce][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo apt-sources 0.3.0 impl#[YesNoForce][FromStr], Selfrust-analyzer cargo apt-sources 0.3.0 impl#[YesNoForce][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> { |
| 132 | match s { |
| 133 | "yes" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo apt-sources 0.3.0 impl#[YesNoForce][FromStr]::Yesrust-analyzer cargo apt-sources 0.3.0 YesNoForce#Yes#), |
| 134 | "no" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo apt-sources 0.3.0 impl#[YesNoForce][FromStr]::Norust-analyzer cargo apt-sources 0.3.0 YesNoForce#No#), |
| 135 | "force" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo apt-sources 0.3.0 impl#[YesNoForce][FromStr]::Forcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#Force#), |
| 136 | _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RepositoryErrorrust-analyzer cargo apt-sources 0.3.0 error/RepositoryError#::YesNoForceFieldInvalidrust-analyzer cargo apt-sources 0.3.0 error/RepositoryError#YesNoForceFieldInvalid#), |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#> for Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 142 | fn fromrust-analyzer cargo apt-sources 0.3.0 impl#[String][`From<&YesNoForce>`]from().(value: &YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#) -> Selfrust-analyzer cargo apt-sources 0.3.0 impl#[String][`From<&YesNoForce>`] { |
| 143 | match value { |
| 144 | YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#::Yesrust-analyzer cargo apt-sources 0.3.0 YesNoForce#Yes# => "yes".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 145 | YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#::Norust-analyzer cargo apt-sources 0.3.0 YesNoForce#No# => "no".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 146 | YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#::Forcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#Force# => "force".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce# { |
| 152 | fn fmtrust-analyzer cargo apt-sources 0.3.0 impl#[YesNoForce][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 153 | let s = match self { |
| 154 | YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#::Yesrust-analyzer cargo apt-sources 0.3.0 YesNoForce#Yes# => "yes", |
| 155 | YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#::Norust-analyzer cargo apt-sources 0.3.0 YesNoForce#No# => "no", |
| 156 | YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#::Forcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#Force# => "force", |
| 157 | }; |
| 158 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{s}") |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | fn deserialize_typesrust-analyzer cargo apt-sources 0.3.0 deserialize_types().(text: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#>, RepositoryErrorrust-analyzer cargo apt-sources 0.3.0 error/RepositoryError#> { |
| 163 | text.split_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_whitespace().() |
| 164 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::from_strrust-analyzer cargo apt-sources 0.3.0 impl#[RepositoryType][FromStr]from_str().) |
| 165 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#>, RepositoryErrorrust-analyzer cargo apt-sources 0.3.0 error/RepositoryError#>>() |
| 166 | } |
| 167 | |
| 168 | fn serialize_typesrust-analyzer cargo apt-sources 0.3.0 serialize_types().(files: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#>) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 169 | files.iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|rt| rt.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).joinrust-analyzer cargo itertools 0.14.0 Itertools#join().("\n") |
| 170 | } |
| 171 | |
| 172 | fn deserialize_urisrust-analyzer cargo apt-sources 0.3.0 deserialize_uris().(text: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Urlrust-analyzer cargo url 2.5.8 Url#>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 173 | // TODO: bad error type |
| 174 | text.split_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_whitespace().() |
| 175 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Urlrust-analyzer cargo url 2.5.8 Url#::from_strrust-analyzer cargo url 2.5.8 impl#[Url][FromStr]from_str().) |
| 176 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Urlrust-analyzer cargo url 2.5.8 Url#>, _>>() |
| 177 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) // TODO: bad error type |
| 178 | } |
| 179 | |
| 180 | fn serialize_urisrust-analyzer cargo apt-sources 0.3.0 serialize_uris().(uris: &[Urlrust-analyzer cargo url 2.5.8 Url#]) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 181 | uris.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|u| u.as_strrust-analyzer cargo url 2.5.8 impl#[Url]as_str().()).joinrust-analyzer cargo itertools 0.14.0 Itertools#join().(" ") |
| 182 | } |
| 183 | |
| 184 | fn deserialize_string_chainrust-analyzer cargo apt-sources 0.3.0 deserialize_string_chain().(text: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 185 | // TODO: bad error type |
| 186 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(text.split_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_whitespace().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| x.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()) |
| 187 | } |
| 188 | |
| 189 | fn deserialize_yesnorust-analyzer cargo apt-sources 0.3.0 deserialize_yesno().(text: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, RepositoryErrorrust-analyzer cargo apt-sources 0.3.0 error/RepositoryError#> { |
| 190 | // TODO: bad error type |
| 191 | match text { |
| 192 | "yes" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(true), |
| 193 | "no" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false), |
| 194 | _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RepositoryErrorrust-analyzer cargo apt-sources 0.3.0 error/RepositoryError#::YesNoFieldInvalidrust-analyzer cargo apt-sources 0.3.0 error/RepositoryError#YesNoFieldInvalid#), |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | fn serializer_yesnorust-analyzer cargo apt-sources 0.3.0 serializer_yesno().(value: &bool) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 199 | if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().value { |
| 200 | "yes".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 201 | } else { |
| 202 | "no".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | fn serialize_string_chainrust-analyzer cargo apt-sources 0.3.0 serialize_string_chain().(chain: &[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#]) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 207 | chain.joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().(" ") |
| 208 | } |
| 209 | |
| 210 | /// A structure representing APT repository as declared by DEB822 source file |
| 211 | /// |
| 212 | /// According to `sources.list(5)` man pages, only four fields are mandatory: |
| 213 | /// * `Types` either `deb` or/and `deb-src` |
| 214 | /// * `URIs` to repositories holding valid APT structure (unclear if multiple are allowed) |
| 215 | /// * `Suites` usually being distribution codenames |
| 216 | /// * `Component` most of the time `main`, but it's a section of the repository |
| 217 | /// |
| 218 | /// The manpage specifies following optional fields |
| 219 | /// * `Enabled` is a yes/no field, default yes |
| 220 | /// * `Architectures` |
| 221 | /// * `Languages` |
| 222 | /// * `Targets` |
| 223 | /// * `PDiffs` is a yes/no field |
| 224 | /// * `By-Hash` is a yes/no/force field |
| 225 | /// * `Allow-Insecure` is a yes/no field, default no |
| 226 | /// * `Allow-Weak` is a yes/no field, default no |
| 227 | /// * `Allow-Downgrade-To-Insecure` is a yes/no field, default no |
| 228 | /// * `Trusted` us a yes/no field |
| 229 | /// * `Signed-By` is either path to the key or PGP key block |
| 230 | /// * `Check-Valid-Until` is a yes/no field |
| 231 | /// * `Valid-Until-Min` |
| 232 | /// * `Valid-Until-Max` |
| 233 | /// * `Check-Date` is a yes/no field |
| 234 | /// * `Date-Max-Future` |
| 235 | /// * `InRelease-Path` relative path |
| 236 | /// * `Snapshot` either `enable` or a snapshot ID |
| 237 | /// |
| 238 | /// The unit tests of APT use: |
| 239 | /// * `Description` |
| 240 | /// |
| 241 | /// The RepoLib tool uses: |
| 242 | /// * `X-Repolib-Name` identifier for own reference, meaningless for APT |
| 243 | /// |
| 244 | /// Note: Multivalues `*-Add` & `*-Remove` semantics aren't supported. |
| 245 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(FromDeb822rust-analyzer cargo deb822-derive 0.3.1 FromDeb822:, ToDeb822rust-analyzer cargo deb822-derive 0.3.1 ToDeb822:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, /*Eq,*/ Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 246 | pub struct Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# { |
| 247 | /// If `no` (false) the repository is ignored by APT |
| 248 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "Enabled", deserialize_with = deserialize_yesnorust-analyzer cargo apt-sources 0.3.0 deserialize_yesno()., serialize_with = serializer_yesnorust-analyzer cargo apt-sources 0.3.0 serializer_yesno().)] |
| 249 | // TODO: support for `default` if omitted is missing |
| 250 | pub enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool>, |
| 251 | |
| 252 | /// The value `RepositoryType::Binary` (`deb`) or/and `RepositoryType::Source` (`deb-src`) |
| 253 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "Types", deserialize_with = deserialize_typesrust-analyzer cargo apt-sources 0.3.0 deserialize_types()., serialize_with = serialize_typesrust-analyzer cargo apt-sources 0.3.0 serialize_types().)] |
| 254 | pub typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#>, // consider alternative, closed set |
| 255 | /// The address of the repository |
| 256 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "URIs", deserialize_with = deserialize_urisrust-analyzer cargo apt-sources 0.3.0 deserialize_uris()., serialize_with = serialize_urisrust-analyzer cargo apt-sources 0.3.0 serialize_uris().)] |
| 257 | pub urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Urlrust-analyzer cargo url 2.5.8 Url#>, // according to Debian that's URI, but this type is more advanced than URI from `http` crate |
| 258 | /// The distribution name as codename or suite type (like `stable` or `testing`) |
| 259 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "Suites", deserialize_with = deserialize_string_chainrust-analyzer cargo apt-sources 0.3.0 deserialize_string_chain()., serialize_with = serialize_string_chainrust-analyzer cargo apt-sources 0.3.0 serialize_string_chain().)] |
| 260 | pub suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 261 | /// (Optional) Section of the repository, usually `main`, `contrib` or `non-free` |
| 262 | /// return `None` if repository is Flat Repository Format (<https://wiki.debian.org/DebianRepository/Format#Flat_Repository_Format>) |
| 263 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "Components", deserialize_with = deserialize_string_chainrust-analyzer cargo apt-sources 0.3.0 deserialize_string_chain()., serialize_with = serialize_string_chainrust-analyzer cargo apt-sources 0.3.0 serialize_string_chain().)] |
| 264 | pub componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, |
| 265 | |
| 266 | /// (Optional) Architectures binaries from this repository run on |
| 267 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "Architectures", deserialize_with = deserialize_string_chainrust-analyzer cargo apt-sources 0.3.0 deserialize_string_chain()., serialize_with = serialize_string_chainrust-analyzer cargo apt-sources 0.3.0 serialize_string_chain().)] |
| 268 | pub architecturesrust-analyzer cargo apt-sources 0.3.0 Repository#architectures.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, |
| 269 | /// (Optional) Translations support to download |
| 270 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "Languages", deserialize_with = deserialize_string_chainrust-analyzer cargo apt-sources 0.3.0 deserialize_string_chain()., serialize_with = serialize_string_chainrust-analyzer cargo apt-sources 0.3.0 serialize_string_chain().)] |
| 271 | pub languagesrust-analyzer cargo apt-sources 0.3.0 Repository#languages.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, // TODO: Option is redundant to empty vectors |
| 272 | /// (Optional) Download targets to acquire from this source |
| 273 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "Targets", deserialize_with = deserialize_string_chainrust-analyzer cargo apt-sources 0.3.0 deserialize_string_chain()., serialize_with = serialize_string_chainrust-analyzer cargo apt-sources 0.3.0 serialize_string_chain().)] |
| 274 | pub targetsrust-analyzer cargo apt-sources 0.3.0 Repository#targets.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>, |
| 275 | /// (Optional) Controls if APT should try PDiffs instead of downloading indexes entirely; if not set defaults to configuration option `Acquire::PDiffs` |
| 276 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "PDiffs", deserialize_with = deserialize_yesnorust-analyzer cargo apt-sources 0.3.0 deserialize_yesno().)] |
| 277 | pub pdiffsrust-analyzer cargo apt-sources 0.3.0 Repository#pdiffs.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool>, |
| 278 | /// (Optional) Controls if APT should try to acquire indexes via a URI constructed from a hashsum of the expected file |
| 279 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "By-Hash")] |
| 280 | pub by_hashrust-analyzer cargo apt-sources 0.3.0 Repository#by_hash.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#>, |
| 281 | /// (Optional) If yes circumvents parts of `apt-secure`, don't thread lightly |
| 282 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "Allow-Insecure")] |
| 283 | pub allow_insecurerust-analyzer cargo apt-sources 0.3.0 Repository#allow_insecure.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool>, // TODO: redundant option, not present = default no |
| 284 | /// (Optional) If yes circumvents parts of `apt-secure`, don't thread lightly |
| 285 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "Allow-Weak")] |
| 286 | pub allow_weakrust-analyzer cargo apt-sources 0.3.0 Repository#allow_weak.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool>, // TODO: redundant option, not present = default no |
| 287 | /// (Optional) If yes circumvents parts of `apt-secure`, don't thread lightly |
| 288 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "Allow-Downgrade-To-Insecure")] |
| 289 | pub allow_downgrade_to_insecurerust-analyzer cargo apt-sources 0.3.0 Repository#allow_downgrade_to_insecure.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool>, // TODO: redundant option, not present = default no |
| 290 | /// (Optional) If set forces whether APT considers source as rusted or no (default not present is a third state) |
| 291 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "Trusted")] |
| 292 | pub trustedrust-analyzer cargo apt-sources 0.3.0 Repository#trusted.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool>, |
| 293 | /// (Optional) Contains either absolute path to GPG keyring or embedded GPG public key block, if not set APT uses all trusted keys; |
| 294 | /// I can't find example of using with fingerprints |
| 295 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "Signed-By")] |
| 296 | pub signaturerust-analyzer cargo apt-sources 0.3.0 Repository#signature.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Signaturerust-analyzer cargo apt-sources 0.3.0 signature/Signature#>, |
| 297 | |
| 298 | /// (Optional) Field ignored by APT but used by RepoLib to identify repositories, Ubuntu sources contain them |
| 299 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "X-Repolib-Name")] |
| 300 | pub x_repolib_namerust-analyzer cargo apt-sources 0.3.0 Repository#x_repolib_name.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, // this supports RepoLib still used by PopOS, even if removed from Debian/Ubuntu |
| 301 | |
| 302 | /// (Optional) Field not present in the man page, but used in APT unit tests, potentially to hold the repository description |
| 303 | #[deb822rust-analyzer cargo deb822-derive 0.3.1 deb822:(field = "Description")] |
| 304 | pub descriptionrust-analyzer cargo apt-sources 0.3.0 Repository#description.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, // options: HashMap<String, String> // My original parser kept remaining optional fields in the hash map, is this right approach? |
| 305 | } |
| 306 | |
| 307 | impl Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# { |
| 308 | /// Returns slice of strings containing suites for which this repository provides |
| 309 | pub fn suitesrust-analyzer cargo apt-sources 0.3.0 impl#[Repository]suites().(&self) -> &[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#] { |
| 310 | self.suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites..as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().() |
| 311 | } |
| 312 | |
| 313 | /// Returns the repository types (deb/deb-src) |
| 314 | pub fn typesrust-analyzer cargo apt-sources 0.3.0 impl#[Repository]types().(&self) -> &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#> { |
| 315 | &self.typesrust-analyzer cargo apt-sources 0.3.0 Repository#types. |
| 316 | } |
| 317 | |
| 318 | /// Returns the repository URIs |
| 319 | pub fn urisrust-analyzer cargo apt-sources 0.3.0 impl#[Repository]uris().(&self) -> &[Urlrust-analyzer cargo url 2.5.8 Url#] { |
| 320 | &self.urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris. |
| 321 | } |
| 322 | |
| 323 | /// Returns the repository components |
| 324 | pub fn componentsrust-analyzer cargo apt-sources 0.3.0 impl#[Repository]components().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#]> { |
| 325 | self.componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().() |
| 326 | } |
| 327 | |
| 328 | /// Returns the repository architectures |
| 329 | pub fn architecturesrust-analyzer cargo apt-sources 0.3.0 impl#[Repository]architectures().(&self) -> &[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#] { |
| 330 | self.architecturesrust-analyzer cargo apt-sources 0.3.0 Repository#architectures..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(&[]) |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | /// Container for multiple `Repository` specifications as single `.sources` file may contain as per specification |
| 335 | #[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:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 336 | pub struct Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#>); |
| 337 | |
| 338 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories# { |
| 339 | /// Creates a default instance by loading repositories from /etc/apt/ |
| 340 | /// |
| 341 | /// Errors are logged as warnings (if the `tracing` feature is enabled) but |
| 342 | /// don't prevent loading valid repositories (like APT does) |
| 343 | fn defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][Default]default().() -> Selfrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][Default] { |
| 344 | let (repos, errors) = Selfrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][Default]::load_from_directoryrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]load_from_directory().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("/etc/apt")); |
| 345 | |
| 346 | // Log any errors encountered, but continue (like APT) |
| 347 | #[cfg(feature = "tracing")] |
| 348 | for error in errors { |
| 349 | tracingrust-analyzer cargo tracing 0.1.44 crate/::warnrust-analyzer cargo tracing 0.1.44 macros/warn!!("Failed to load APT source: {}", error); |
| 350 | } |
| 351 | |
| 352 | // Without tracing feature, errors are silently ignored |
| 353 | #[cfg(not(feature = "tracing"))] |
| 354 | let _ = errors; |
| 355 | |
| 356 | repos |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | impl Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories# { |
| 361 | /// Creates empty container of repositories |
| 362 | pub fn emptyrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]empty().() -> Selfrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories] { |
| 363 | Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().()) |
| 364 | } |
| 365 | |
| 366 | /// Creates repositories from container consisting `Repository` instances |
| 367 | pub fn newrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]new().<Container>(container: Container) -> Selfrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories] |
| 368 | where |
| 369 | Container: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#>>, |
| 370 | { |
| 371 | Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#(container.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().()) |
| 372 | } |
| 373 | |
| 374 | /// Load repositories from a directory (e.g., /etc/apt/) |
| 375 | /// |
| 376 | /// This will load: |
| 377 | /// - sources.list file from the directory |
| 378 | /// - All *.list files from sources.list.d/ subdirectory (in lexicographical order) |
| 379 | /// - All *.sources files from sources.list.d/ subdirectory (in lexicographical order) |
| 380 | /// |
| 381 | /// Returns a tuple of (successfully loaded repositories, errors encountered). |
| 382 | /// This method is resilient like APT - errors in individual files don't prevent |
| 383 | /// loading other valid repositories. |
| 384 | /// |
| 385 | /// <div class="warning"> |
| 386 | /// This loads all repositories from all files, but information about which file they're |
| 387 | /// loaded from is **lost** in the process.u |
| 388 | /// </div> |
| 389 | pub fn load_from_directoryrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]load_from_directory().(path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> (Selfrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories], Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<LoadErrorrust-analyzer cargo apt-sources 0.3.0 error/LoadError#>) { |
| 390 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/; |
| 391 | |
| 392 | let mut all_repositories = Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::emptyrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]empty().(); |
| 393 | let mut errors = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 394 | |
| 395 | // Process main sources.list file if it exists |
| 396 | let main_sources = path.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("sources.list"); |
| 397 | #[cfg(not(feature = "legacy"))] |
| 398 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!( |
| 399 | "WARNING! `{}` hasn't been read as `legacy` support hadn't been enabled during build.", |
| 400 | main_sources.display() |
| 401 | ); |
| 402 | #[cfg(feature = "legacy")] |
| 403 | if main_sources.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() { |
| 404 | match fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(&main_sources) { |
| 405 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(content) => { |
| 406 | match LegacyRepositoriesrust-analyzer cargo apt-sources 0.3.0 legacy/LegacyRepositories#::from_strrust-analyzer cargo apt-sources 0.3.0 legacy/impl#[LegacyRepositories][FromStr]from_str().(&content)/*Self::parse_legacy_format(&content)*/ { |
| 407 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(repos) => { |
| 408 | // let legacy_repos = .collect::<Vec<Repository>, _>>(); |
| 409 | all_repositories.extendrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]extend().(repos.repositoriesrust-analyzer cargo apt-sources 0.3.0 legacy/impl#[LegacyRepositories]repositories().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|l| l.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())) |
| 410 | }, |
| 411 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => errors.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(LoadErrorrust-analyzer cargo apt-sources 0.3.0 error/LoadError#::Parserust-analyzer cargo apt-sources 0.3.0 error/LoadError#Parse# { |
| 412 | pathrust-analyzer cargo apt-sources 0.3.0 error/LoadError#Parse#path.: main_sources, |
| 413 | errorrust-analyzer cargo apt-sources 0.3.0 error/LoadError#Parse#error.: e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), // TODO [MF]: doesn't look right, we shall have error type for every kind |
| 414 | }), |
| 415 | } |
| 416 | } |
| 417 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => errors.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(LoadErrorrust-analyzer cargo apt-sources 0.3.0 error/LoadError#::Iorust-analyzer cargo apt-sources 0.3.0 error/LoadError#Io# { |
| 418 | pathrust-analyzer cargo apt-sources 0.3.0 error/LoadError#Io#path.: main_sources, |
| 419 | errorrust-analyzer cargo apt-sources 0.3.0 error/LoadError#Io#error.: e, |
| 420 | }), |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | // Process files from sources.list.d/ directory |
| 425 | let sources_d = path.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("sources.list.d"); |
| 426 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().sources_d.is_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_dir().() { |
| 427 | return (all_repositories, errors); |
| 428 | } |
| 429 | |
| 430 | let entries = match fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_dir().(&sources_d) { |
| 431 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(entries) => entries, |
| 432 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => { |
| 433 | errors.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(LoadErrorrust-analyzer cargo apt-sources 0.3.0 error/LoadError#::DirectoryReadrust-analyzer cargo apt-sources 0.3.0 error/LoadError#DirectoryRead# { |
| 434 | pathrust-analyzer cargo apt-sources 0.3.0 error/LoadError#DirectoryRead#path.: sources_d, |
| 435 | errorrust-analyzer cargo apt-sources 0.3.0 error/LoadError#DirectoryRead#error.: e, |
| 436 | }); |
| 437 | return (all_repositories, errors); |
| 438 | } |
| 439 | }; |
| 440 | |
| 441 | // Collect and sort entries lexicographically like APT does |
| 442 | let mut entry_paths: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = entries |
| 443 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|entry| entry.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()) |
| 444 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|entry| entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().()) |
| 445 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|p| p.is_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_file().()) |
| 446 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|p| { |
| 447 | p.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_name().() |
| 448 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|n| n.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().()) |
| 449 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|n| n.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(".list") || n.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(".sources")) |
| 450 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(false) |
| 451 | }) |
| 452 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 453 | entry_paths.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().(); |
| 454 | |
| 455 | for file_path in entry_paths { |
| 456 | let file_name = file_path.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_name().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|n| n.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().()).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(""); |
| 457 | |
| 458 | let content = match fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(&file_path) { |
| 459 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(content) => content, |
| 460 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => { |
| 461 | errors.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(LoadErrorrust-analyzer cargo apt-sources 0.3.0 error/LoadError#::Iorust-analyzer cargo apt-sources 0.3.0 error/LoadError#Io# { |
| 462 | pathrust-analyzer cargo apt-sources 0.3.0 error/LoadError#Io#path.: file_path, |
| 463 | errorrust-analyzer cargo apt-sources 0.3.0 error/LoadError#Io#error.: e, |
| 464 | }); |
| 465 | continue; |
| 466 | } |
| 467 | }; |
| 468 | |
| 469 | let parse_result = if file_name.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(".list") { |
| 470 | #[cfg(not(feature = "legacy"))] |
| 471 | { |
| 472 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("WARNING! `{file_name}` hasn't been read as `legacy` support hadn't been enabled during build."); |
| 473 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(LoadErrorrust-analyzer cargo apt-sources 0.3.0 error/LoadError#::UnsupportedLegacyFormat) |
| 474 | } |
| 475 | #[cfg(feature = "legacy")] |
| 476 | LegacyRepositoriesrust-analyzer cargo apt-sources 0.3.0 legacy/LegacyRepositories#::from_strrust-analyzer cargo apt-sources 0.3.0 legacy/impl#[LegacyRepositories][FromStr]from_str().(&content) |
| 477 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|repos| repos.repositoriesrust-analyzer cargo apt-sources 0.3.0 legacy/impl#[LegacyRepositories]repositories().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|l| l.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()) |
| 478 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| LoadErrorrust-analyzer cargo apt-sources 0.3.0 error/LoadError#::Parserust-analyzer cargo apt-sources 0.3.0 error/LoadError#Parse# { |
| 479 | pathrust-analyzer cargo apt-sources 0.3.0 error/LoadError#Parse#path.: file_path, |
| 480 | errorrust-analyzer cargo apt-sources 0.3.0 error/LoadError#Parse#error.: e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), // TODO [MF]: looks like it's time for `thiserror` |
| 481 | }) |
| 482 | } else if file_name.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(".sources") { |
| 483 | content |
| 484 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#>() |
| 485 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|repos| repos.0rust-analyzer cargo apt-sources 0.3.0 Repositories#0.) |
| 486 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| LoadErrorrust-analyzer cargo apt-sources 0.3.0 error/LoadError#::Parserust-analyzer cargo apt-sources 0.3.0 error/LoadError#Parse# { |
| 487 | pathrust-analyzer cargo apt-sources 0.3.0 error/LoadError#Parse#path.: file_path, |
| 488 | errorrust-analyzer cargo apt-sources 0.3.0 error/LoadError#Parse#error.: e, |
| 489 | }) |
| 490 | } else { |
| 491 | continue; |
| 492 | }; |
| 493 | |
| 494 | match parse_result { |
| 495 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(repos) => all_repositories.extendrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]extend().(repos), |
| 496 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => errors.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(e), |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | (all_repositories, errors) |
| 501 | } |
| 502 | |
| 503 | /// Load repositories from a directory, failing on first error |
| 504 | /// |
| 505 | /// Use this when you want strict error handling and need the loading |
| 506 | /// to stop at the first problem encountered. |
| 507 | pub fn load_from_directory_strictrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]load_from_directory_strict().(path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories], LoadErrorrust-analyzer cargo apt-sources 0.3.0 error/LoadError#> { |
| 508 | let (repos, errors) = Selfrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]::load_from_directoryrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]load_from_directory().(path); |
| 509 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(error) = errors.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().nextrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/impl#[`IntoIter<T, A>`][Iterator]next().() { |
| 510 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) |
| 511 | } else { |
| 512 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(repos) |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | /// Push a new repository |
| 517 | pub fn pushrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]push().(&mut self, repo: Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#) { |
| 518 | self.0rust-analyzer cargo apt-sources 0.3.0 Repositories#0..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(repo); |
| 519 | } |
| 520 | |
| 521 | /// Retain repositories matching a predicate |
| 522 | pub fn retainrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]retain().<F>(&mut self, f: F) |
| 523 | where |
| 524 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#) -> bool, |
| 525 | { |
| 526 | self.0rust-analyzer cargo apt-sources 0.3.0 Repositories#0..retainrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]retain().(f); |
| 527 | } |
| 528 | |
| 529 | /// Get iterator over repositories |
| 530 | pub fn iterrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter().(&self) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::Iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/Iter#<'_, Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#> { |
| 531 | self.0rust-analyzer cargo apt-sources 0.3.0 Repositories#0..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 532 | } |
| 533 | |
| 534 | /// Get mutable iterator over repositories |
| 535 | pub fn iter_mutrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter_mut().(&mut self) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::IterMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/IterMut#<'_, Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#> { |
| 536 | self.0rust-analyzer cargo apt-sources 0.3.0 Repositories#0..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().() |
| 537 | } |
| 538 | |
| 539 | /// Extend with an iterator of repositories |
| 540 | pub fn extendrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]extend().<I>(&mut self, iter: I) |
| 541 | where |
| 542 | I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#>, |
| 543 | { |
| 544 | self.0rust-analyzer cargo apt-sources 0.3.0 Repositories#0..extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(iter); |
| 545 | } |
| 546 | |
| 547 | /// Check if empty |
| 548 | pub fn is_emptyrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]is_empty().(&self) -> bool { |
| 549 | self.0rust-analyzer cargo apt-sources 0.3.0 Repositories#0..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories# { |
| 554 | type Errrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][FromStr]Err# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#; |
| 555 | |
| 556 | fn from_strrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][FromStr], Selfrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> { |
| 557 | let deb822: deb822_fastrust-analyzer cargo deb822-fast 0.2.3 crate/::Deb822rust-analyzer cargo deb822-fast 0.2.3 Deb822# = |
| 558 | s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e: deb822_fastrust-analyzer cargo deb822-fast 0.2.3 crate/::Errorrust-analyzer cargo deb822-fast 0.2.3 Error#| e.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 559 | |
| 560 | let repos = deb822 |
| 561 | .iterrust-analyzer cargo deb822-fast 0.2.3 impl#[Deb822]iter().() |
| 562 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#::from_paragraphrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][`FromDeb822Paragraph<P>`]from_paragraph().) |
| 563 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#>, Selfrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#>>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 564 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#(repos)) |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories# { |
| 569 | fn fmtrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 570 | let result = self |
| 571 | .0rust-analyzer cargo apt-sources 0.3.0 Repositories#0. |
| 572 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 573 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|r| { |
| 574 | let p: deb822_fastrust-analyzer cargo deb822-fast 0.2.3 crate/::Paragraphrust-analyzer cargo deb822-fast 0.2.3 Paragraph# = r.to_paragraphrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][`ToDeb822Paragraph<P>`]to_paragraph().(); |
| 575 | p.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 576 | }) |
| 577 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>() |
| 578 | .joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().("\n"); |
| 579 | f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(&result) |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | impl Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories# { |
| 584 | type Targetrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][Deref]Target# = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#>; |
| 585 | |
| 586 | fn derefrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][Deref]deref().(&self) -> &Selfrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories][Deref]::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# { |
| 587 | &self.0rust-analyzer cargo apt-sources 0.3.0 Repositories#0. |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | #[cfg(test)] |
| 592 | mod testsrust-analyzer cargo apt-sources 0.3.0 tests/ { |
| 593 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#, strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#}; |
| 594 | |
| 595 | use indocrust-analyzer cargo indoc 2.0.7 crate/::indocrust-analyzer cargo indoc 2.0.7 indoc!; |
| 596 | use urlrust-analyzer cargo url 2.5.8 crate/::Urlrust-analyzer cargo url 2.5.8 Url#; |
| 597 | |
| 598 | use craterust-analyzer cargo apt-sources 0.3.0 crate/::{signaturerust-analyzer cargo apt-sources 0.3.0 signature/::Signaturerust-analyzer cargo apt-sources 0.3.0 signature/Signature#, Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#, Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#, RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#}; |
| 599 | |
| 600 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 601 | fn test_not_machine_readablerust-analyzer cargo apt-sources 0.3.0 tests/test_not_machine_readable().() { |
| 602 | let s = indocrust-analyzer cargo indoc 2.0.7 indoc!!( |
| 603 | r#" |
| 604 | deb [arch=arm64 signed-by=/usr/share/keyrings/docker.gpg] http://ports.ubuntu.com/ noble stable |
| 605 | "# |
| 606 | ); |
| 607 | let ret = s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#>(); |
| 608 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ret.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 609 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ret.unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(), "missing field: Types".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 610 | } |
| 611 | |
| 612 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 613 | fn test_parse_flat_reporust-analyzer cargo apt-sources 0.3.0 tests/test_parse_flat_repo().() { |
| 614 | let s = indocrust-analyzer cargo indoc 2.0.7 indoc!! {r#" |
| 615 | Types: deb |
| 616 | URIs: http://ports.ubuntu.com/ |
| 617 | Suites: ./ |
| 618 | Architectures: arm64 |
| 619 | "#}; |
| 620 | |
| 621 | let repos = s |
| 622 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#>() |
| 623 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Shall be parsed flawlessly"); |
| 624 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(repos[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..typesrust-analyzer cargo apt-sources 0.3.0 Repository#types..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&superrust-analyzer cargo apt-sources 0.3.0 crate/::RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#)); |
| 625 | } |
| 626 | |
| 627 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 628 | fn test_parse_without_architecturesrust-analyzer cargo apt-sources 0.3.0 tests/test_parse_without_architectures().() { |
| 629 | // Architectures is optional; Debian's own default .sources omits it. |
| 630 | let s = indocrust-analyzer cargo indoc 2.0.7 indoc!! {r#" |
| 631 | Types: deb |
| 632 | URIs: http://deb.debian.org/debian |
| 633 | Suites: trixie |
| 634 | Components: main |
| 635 | Signed-By: /usr/share/keyrings/debian-archive-keyring.pgp |
| 636 | "#}; |
| 637 | |
| 638 | let repos = s |
| 639 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#>() |
| 640 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Shall be parsed flawlessly"); |
| 641 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(repos[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..architecturesrust-analyzer cargo apt-sources 0.3.0 Repository#architectures., Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 642 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(repos[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..architecturesrust-analyzer cargo apt-sources 0.3.0 impl#[Repository]architectures().(), &[] as &[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#]); |
| 643 | } |
| 644 | |
| 645 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 646 | fn test_parse_w_keyblockrust-analyzer cargo apt-sources 0.3.0 tests/test_parse_w_keyblock().() { |
| 647 | let s = indocrust-analyzer cargo indoc 2.0.7 indoc!!( |
| 648 | r#" |
| 649 | Types: deb |
| 650 | URIs: http://ports.ubuntu.com/ |
| 651 | Suites: noble |
| 652 | Components: stable |
| 653 | Architectures: arm64 |
| 654 | Signed-By: |
| 655 | -----BEGIN PGP PUBLIC KEY BLOCK----- |
| 656 | . |
| 657 | mDMEY865UxYJKwYBBAHaRw8BAQdAd7Z0srwuhlB6JKFkcf4HU4SSS/xcRfwEQWzr |
| 658 | crf6AEq0SURlYmlhbiBTdGFibGUgUmVsZWFzZSBLZXkgKDEyL2Jvb2t3b3JtKSA8 |
| 659 | ZGViaWFuLXJlbGVhc2VAbGlzdHMuZGViaWFuLm9yZz6IlgQTFggAPhYhBE1k/sEZ |
| 660 | wgKQZ9bnkfjSWFuHg9SBBQJjzrlTAhsDBQkPCZwABQsJCAcCBhUKCQgLAgQWAgMB |
| 661 | Ah4BAheAAAoJEPjSWFuHg9SBSgwBAP9qpeO5z1s5m4D4z3TcqDo1wez6DNya27QW |
| 662 | WoG/4oBsAQCEN8Z00DXagPHbwrvsY2t9BCsT+PgnSn9biobwX7bDDg== |
| 663 | =5NZE |
| 664 | -----END PGP PUBLIC KEY BLOCK----- |
| 665 | "# |
| 666 | ); |
| 667 | |
| 668 | let repos = s |
| 669 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#>() |
| 670 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Shall be parsed flawlessly"); |
| 671 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(repos[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..typesrust-analyzer cargo apt-sources 0.3.0 Repository#types..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&superrust-analyzer cargo apt-sources 0.3.0 crate/::RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#)); |
| 672 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(repos[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..signaturerust-analyzer cargo apt-sources 0.3.0 Repository#signature., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Signaturerust-analyzer cargo apt-sources 0.3.0 signature/Signature#::KeyBlockrust-analyzer cargo apt-sources 0.3.0 signature/Signature#KeyBlock#(_)))); |
| 673 | } |
| 674 | |
| 675 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 676 | fn test_parse_w_keypathrust-analyzer cargo apt-sources 0.3.0 tests/test_parse_w_keypath().() { |
| 677 | let s = indocrust-analyzer cargo indoc 2.0.7 indoc!!( |
| 678 | r#" |
| 679 | Types: deb |
| 680 | URIs: http://ports.ubuntu.com/ |
| 681 | Suites: noble |
| 682 | Components: stable |
| 683 | Architectures: arm64 |
| 684 | Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg |
| 685 | "# |
| 686 | ); |
| 687 | |
| 688 | let reps = s |
| 689 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#>() |
| 690 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Shall be parsed flawlessly"); |
| 691 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reps[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..typesrust-analyzer cargo apt-sources 0.3.0 Repository#types..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&superrust-analyzer cargo apt-sources 0.3.0 crate/::RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#)); |
| 692 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(reps[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..signaturerust-analyzer cargo apt-sources 0.3.0 Repository#signature., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Signaturerust-analyzer cargo apt-sources 0.3.0 signature/Signature#::KeyPathrust-analyzer cargo apt-sources 0.3.0 signature/Signature#KeyPath#(_)))); |
| 693 | } |
| 694 | |
| 695 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 696 | fn test_serializerust-analyzer cargo apt-sources 0.3.0 tests/test_serialize().() { |
| 697 | //let repos = Repositories::empty(); |
| 698 | let repos = Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::newrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]new().([Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# { |
| 699 | enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(true), // TODO: looks odd, as only `Enabled: no` in meaningful |
| 700 | typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#]), |
| 701 | architecturesrust-analyzer cargo apt-sources 0.3.0 Repository#architectures.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["arm64".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()]), |
| 702 | urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Urlrust-analyzer cargo url 2.5.8 Url#::from_strrust-analyzer cargo url 2.5.8 impl#[Url][FromStr]from_str().("https://deb.debian.org/debian").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()], |
| 703 | suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["jammy".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()], |
| 704 | componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()]), |
| 705 | signaturerust-analyzer cargo apt-sources 0.3.0 Repository#signature.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 706 | x_repolib_namerust-analyzer cargo apt-sources 0.3.0 Repository#x_repolib_name.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 707 | languagesrust-analyzer cargo apt-sources 0.3.0 Repository#languages.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 708 | targetsrust-analyzer cargo apt-sources 0.3.0 Repository#targets.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 709 | pdiffsrust-analyzer cargo apt-sources 0.3.0 Repository#pdiffs.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 710 | ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().() |
| 711 | }]); |
| 712 | let text = repos.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 713 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 714 | text, |
| 715 | indocrust-analyzer cargo indoc 2.0.7 indoc!! {r#" |
| 716 | Enabled: yes |
| 717 | Types: deb |
| 718 | URIs: https://deb.debian.org/debian |
| 719 | Suites: jammy |
| 720 | Components: main |
| 721 | Architectures: arm64 |
| 722 | "#} |
| 723 | ); |
| 724 | } |
| 725 | |
| 726 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 727 | fn test_yesnoforce_to_stringrust-analyzer cargo apt-sources 0.3.0 tests/test_yesnoforce_to_string().() { |
| 728 | let yes = craterust-analyzer cargo apt-sources 0.3.0 crate/::YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#::Yesrust-analyzer cargo apt-sources 0.3.0 YesNoForce#Yes#; |
| 729 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(yes.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "yes"); |
| 730 | |
| 731 | let no = craterust-analyzer cargo apt-sources 0.3.0 crate/::YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#::Norust-analyzer cargo apt-sources 0.3.0 YesNoForce#No#; |
| 732 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(no.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "no"); |
| 733 | |
| 734 | let force = craterust-analyzer cargo apt-sources 0.3.0 crate/::YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#::Forcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#Force#; |
| 735 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(force.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "force"); |
| 736 | } |
| 737 | |
| 738 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 739 | fn test_repository_type_displayrust-analyzer cargo apt-sources 0.3.0 tests/test_repository_type_display().() { |
| 740 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "deb"); |
| 741 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "deb-src"); |
| 742 | } |
| 743 | |
| 744 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 745 | fn test_yesnoforce_displayrust-analyzer cargo apt-sources 0.3.0 tests/test_yesnoforce_display().() { |
| 746 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(craterust-analyzer cargo apt-sources 0.3.0 crate/::YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#::Yesrust-analyzer cargo apt-sources 0.3.0 YesNoForce#Yes#.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "yes"); |
| 747 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(craterust-analyzer cargo apt-sources 0.3.0 crate/::YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#::Norust-analyzer cargo apt-sources 0.3.0 YesNoForce#No#.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "no"); |
| 748 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(craterust-analyzer cargo apt-sources 0.3.0 crate/::YesNoForcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#::Forcerust-analyzer cargo apt-sources 0.3.0 YesNoForce#Force#.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "force"); |
| 749 | } |
| 750 | |
| 751 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 752 | fn test_repositories_is_emptyrust-analyzer cargo apt-sources 0.3.0 tests/test_repositories_is_empty().() { |
| 753 | let empty_repos = Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::emptyrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]empty().(); |
| 754 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(empty_repos.is_emptyrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]is_empty().()); |
| 755 | |
| 756 | let mut repos = Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::emptyrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]empty().(); |
| 757 | repos.pushrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]push().(Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().()); |
| 758 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().repos.is_emptyrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]is_empty().()); |
| 759 | } |
| 760 | |
| 761 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 762 | fn test_repository_gettersrust-analyzer cargo apt-sources 0.3.0 tests/test_repository_getters().() { |
| 763 | let repo = Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# { |
| 764 | typesrust-analyzer cargo apt-sources 0.3.0 Repository#types.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#, RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#]), |
| 765 | urisrust-analyzer cargo apt-sources 0.3.0 Repository#uris.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().("http://example.com/debian").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()], |
| 766 | suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["stable".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()], |
| 767 | componentsrust-analyzer cargo apt-sources 0.3.0 Repository#components.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "contrib".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]), |
| 768 | architecturesrust-analyzer cargo apt-sources 0.3.0 Repository#architectures.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["amd64".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "arm64".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]), |
| 769 | ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().() |
| 770 | }; |
| 771 | |
| 772 | // Test types getter |
| 773 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 774 | repo.typesrust-analyzer cargo apt-sources 0.3.0 impl#[Repository]types().(), |
| 775 | &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().([RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Binaryrust-analyzer cargo apt-sources 0.3.0 RepositoryType#Binary#, RepositoryTyperust-analyzer cargo apt-sources 0.3.0 RepositoryType#::Sourcerust-analyzer cargo apt-sources 0.3.0 RepositoryType#Source#]) |
| 776 | ); |
| 777 | |
| 778 | // Test uris getter |
| 779 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(repo.urisrust-analyzer cargo apt-sources 0.3.0 impl#[Repository]uris().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), 1); |
| 780 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(repo.urisrust-analyzer cargo apt-sources 0.3.0 impl#[Repository]uris().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "http://example.com/debian"); |
| 781 | |
| 782 | // Test suites getter (existing) |
| 783 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(repo.suitesrust-analyzer cargo apt-sources 0.3.0 impl#[Repository]suites().(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["stable"]); |
| 784 | |
| 785 | // Test components getter |
| 786 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 787 | repo.componentsrust-analyzer cargo apt-sources 0.3.0 impl#[Repository]components().(), |
| 788 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["main".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "contrib".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()].as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().()) |
| 789 | ); |
| 790 | |
| 791 | // Test architectures getter |
| 792 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(repo.architecturesrust-analyzer cargo apt-sources 0.3.0 impl#[Repository]architectures().(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["amd64", "arm64"]); |
| 793 | } |
| 794 | |
| 795 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 796 | fn test_repositories_iterrust-analyzer cargo apt-sources 0.3.0 tests/test_repositories_iter().() { |
| 797 | let mut repos = Repositoriesrust-analyzer cargo apt-sources 0.3.0 Repositories#::emptyrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]empty().(); |
| 798 | repos.pushrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]push().(Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# { |
| 799 | suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["stable".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()], |
| 800 | ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().() |
| 801 | }); |
| 802 | repos.pushrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]push().(Repositoryrust-analyzer cargo apt-sources 0.3.0 Repository# { |
| 803 | suitesrust-analyzer cargo apt-sources 0.3.0 Repository#suites.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["testing".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()], |
| 804 | ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo apt-sources 0.3.0 impl#[Repository][Default]default().() |
| 805 | }); |
| 806 | |
| 807 | // Test iter() |
| 808 | let suites: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = repos.iterrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|r| r.suitesrust-analyzer cargo apt-sources 0.3.0 impl#[Repository]suites().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 809 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(suites.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2); |
| 810 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(suites[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["stable"]); |
| 811 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(suites[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["testing"]); |
| 812 | |
| 813 | // Test iter_mut() - modifying through mutable iterator |
| 814 | for repo in repos.iter_mutrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter_mut().() { |
| 815 | repo.enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(false); |
| 816 | } |
| 817 | |
| 818 | for repo in repos.iterrust-analyzer cargo apt-sources 0.3.0 impl#[Repositories]iter().() { |
| 819 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(repo.enabledrust-analyzer cargo apt-sources 0.3.0 Repository#enabled., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(false)); |
| 820 | } |
| 821 | } |
| 822 | } |