1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! Types and functions that implement the specification of `Polyhorn.toml`
//! files.

use serde::{Deserialize, Serialize};
use std::fs::File;
use std::io::Read;
use std::path::Path;

mod error;

pub use error::Error;

use crate::{android, ios};

/// Specification stored in a `Polyhorn.toml` file.
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct Spec {
    /// Settings related to the app that a Polyhorn project builds.
    pub app: AppSpec,
}

impl Spec {
    /// Attempts to open the specification stored in the `Polyhorn.toml` file at
    /// the given path.
    pub fn open<P>(path: P) -> Result<Spec, Error>
    where
        P: AsRef<Path>,
    {
        let mut file = File::open(path)?;
        let mut bytes = vec![];
        file.read_to_end(&mut bytes)?;
        Ok(toml::from_slice::<Spec>(&bytes)?)
    }
}

/// Settings related to the app that a Polyhorn project builds.
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct AppSpec {
    /// This is the name that will appear on the home screen.
    pub name: String,

    /// This is the human-readable version string. The version string is not
    /// bound to any of the constraints that the version code (for Android) is
    /// bound to. Specifically: this string can consist of any characters, it is
    /// not used for determining an ordering between releases and therefore does
    /// not have to be incrementing.
    pub version: String,

    /// These are iOS-specific settings.
    pub ios: ios::Spec,

    /// These are Android-specific settings.
    pub android: android::Spec,
}