polyhorn_cli/spec/mod.rs
1//! Types and functions that implement the specification of `Polyhorn.toml`
2//! files.
3
4use serde::{Deserialize, Serialize};
5use std::fs::File;
6use std::io::Read;
7use std::path::Path;
8
9mod error;
10
11pub use error::Error;
12
13use crate::{android, ios};
14
15/// Specification stored in a `Polyhorn.toml` file.
16#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
17pub struct Spec {
18 /// Settings related to the app that a Polyhorn project builds.
19 pub app: AppSpec,
20}
21
22impl Spec {
23 /// Attempts to open the specification stored in the `Polyhorn.toml` file at
24 /// the given path.
25 pub fn open<P>(path: P) -> Result<Spec, Error>
26 where
27 P: AsRef<Path>,
28 {
29 let mut file = File::open(path)?;
30 let mut bytes = vec![];
31 file.read_to_end(&mut bytes)?;
32 Ok(toml::from_slice::<Spec>(&bytes)?)
33 }
34}
35
36/// Settings related to the app that a Polyhorn project builds.
37#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
38pub struct AppSpec {
39 /// This is the name that will appear on the home screen.
40 pub name: String,
41
42 /// This is the human-readable version string. The version string is not
43 /// bound to any of the constraints that the version code (for Android) is
44 /// bound to. Specifically: this string can consist of any characters, it is
45 /// not used for determining an ordering between releases and therefore does
46 /// not have to be incrementing.
47 pub version: String,
48
49 /// These are iOS-specific settings.
50 pub ios: ios::Spec,
51
52 /// These are Android-specific settings.
53 pub android: android::Spec,
54}