cml/types/collection.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 crate::types::environment::EnvironmentRef;
6pub use cm_types::{AllowedOffers, Durability, Name};
7use reference_doc::ReferenceDoc;
8use serde::{Deserialize, Serialize};
9
10#[derive(Deserialize, Debug, PartialEq, ReferenceDoc, Serialize)]
11#[serde(deny_unknown_fields)]
12#[reference_doc(fields_as = "list", top_level_doc_after_fields)]
13/// Example:
14///
15/// ```json5
16/// collections: [
17/// {
18/// name: "tests",
19/// durability: "transient",
20/// },
21/// ],
22/// ```
23pub struct Collection {
24 /// The name of the component collection, which is a string of one or
25 /// more of the following characters: `a-z`, `0-9`, `_`, `.`, `-`. The name
26 /// identifies this collection when used in a [reference](#references).
27 pub name: Name,
28
29 /// The duration of child component instances in the collection.
30 /// - `transient`: The instance exists until its parent is stopped or it is
31 /// explicitly destroyed.
32 /// - `single_run`: The instance is started when it is created, and destroyed
33 /// when it is stopped.
34 pub durability: Durability,
35
36 /// If present, the environment that will be
37 /// assigned to instances in this collection, one of
38 /// [`environments`](#environments). If omitted, instances in this collection
39 /// will inherit the same environment assigned to this component.
40 pub environment: Option<EnvironmentRef>,
41
42 /// Constraints on the dynamic offers that target the components in this collection.
43 /// Dynamic offers are specified when calling `fuchsia.component.Realm/CreateChild`.
44 /// - `static_only`: Only those specified in this `.cml` file. No dynamic offers.
45 /// This is the default.
46 /// - `static_and_dynamic`: Both static offers and those specified at runtime
47 /// with `CreateChild` are allowed.
48 pub allowed_offers: Option<AllowedOffers>,
49
50 /// Allow child names up to 1024 characters long instead of the usual 255 character limit.
51 /// Default is false.
52 pub allow_long_names: Option<bool>,
53
54 /// If set to `true`, the data in isolated storage used by dynamic child instances and
55 /// their descendants will persist after the instances are destroyed. A new child instance
56 /// created with the same name will share the same storage path as the previous instance.
57 pub persistent_storage: Option<bool>,
58}