fuchsia_pkg/
package_sets.rs

1// Copyright 2025 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use fuchsia_hash::Hash;
6use fuchsia_url::UnpinnedAbsolutePackageUrl;
7use serde::{Deserialize, Serialize};
8use std::collections::BTreeMap;
9
10/// Package Set Types as specified in RFC-212
11/// https://fuchsia.dev/fuchsia-src/contribute/governance/rfcs/0212_package_sets
12#[derive(Clone, Copy, Hash, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord)]
13#[serde(untagged)]
14pub enum PackageSetType {
15    /// Anchored packages
16    Anchored(AnchoredPackageSetType),
17    /// Upgradable packages
18    Upgradable(UpgradablePackageSetType),
19    /// Discoverable packages
20    Discoverable(DiscoverablePackageSetType),
21}
22
23#[derive(Clone, Copy, Hash, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord)]
24pub enum AnchoredPackageSetType {
25    /// Anchored, permanent packages, also known as static packages
26    #[serde(rename = "anchored_permanent")]
27    Permanent,
28    /// Anchored automatic packages
29    #[serde(rename = "anchored_automatic")]
30    Automatic,
31    /// Anchored on-demand packages
32    #[serde(rename = "anchored_on_demand")]
33    OnDemand,
34}
35
36#[derive(Clone, Copy, Hash, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord)]
37pub enum DiscoverablePackageSetType {
38    #[serde(rename = "discoverable")]
39    Discoverable,
40}
41
42#[derive(Clone, Copy, Hash, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord)]
43pub enum UpgradablePackageSetType {
44    /// Upgradable, permanent packages
45    #[serde(rename = "upgradable_permanent")]
46    Permanent,
47    /// Upgradable, automatic packages
48    #[serde(rename = "upgradable_automatic")]
49    Automatic,
50    /// Upgradable, on-demand packages
51    #[serde(rename = "upgradable_on_demand")]
52    OnDemand,
53}
54
55// The following types are used to enable (de)serialization of the different package set types
56// into one JSON configuration file, as described by
57// https://fuchsia.dev/fuchsia-src/contribute/governance/rfcs/0271_anchored_packages?hl=en#the_dataanchored_packages_file
58// Initially used for the implementation of anchored packages, the format is intended to be usable
59// for all package set types.
60
61/// PackageProperties contains additional properties besides
62/// the package URL that apply to a package and can be provided. It is intended to be extensible.
63#[derive(Clone, Hash, Serialize, Deserialize, Debug, PartialEq, Eq)]
64pub struct PackageProperties {
65    pub hash: Hash,
66}
67
68/// PackageSet encapsulates one set of packages (e.g. the "automatic anchored set")
69/// as a map of its package URL to the package's properties.
70pub type PackageSet = BTreeMap<UnpinnedAbsolutePackageUrl, PackageProperties>;
71
72/// PackageMap is the high level map of packages, containing maps to all the sets
73/// referenced by its set type (e.g. the "on demand upgradable set").
74pub type PackageMap = BTreeMap<PackageSetType, PackageSet>;
75
76/// AnchoredPackageMap is a high level map of packages, similar to the PackageMap type, but
77/// limited to the sets of anchored packages types.
78pub type AnchoredPackageMap = BTreeMap<AnchoredPackageSetType, PackageSet>;