libtmplgen/
types.rs

1//This file is part of tmplgen
2//
3//tmplgen is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//tmplgen is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with tmplgen.  If not, see <http://www.gnu.org/licenses/>.
15
16use serde_derive::Deserialize;
17use std::io::Read;
18
19/// The TemplateBuilder struct, which is used to build a [Template](crate::types::Template)
20pub struct TmplBuilder {
21    pub pkg_name: String,
22    pub pkg_type: Option<PkgType>,
23    pub pkg_info: Option<PkgInfo>,
24}
25
26pub struct Template {
27    pub inner: String,
28    pub name: String,
29}
30
31impl Read for Template {
32    fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
33        self.inner.as_bytes().read(buf)
34    }
35}
36
37/// The PkgType enum, containing all types of packages tmplgen can handle
38#[derive(Copy, Clone, Eq, Ord, PartialOrd, Hash, Debug, PartialEq)]
39pub enum PkgType {
40    Crate,
41    Gem,
42    PerlDist,
43}
44
45/// The Dependencies struct that contains all dependencies a package might have
46#[derive(Clone, Eq, Ord, PartialOrd, Hash, Default, Debug, PartialEq)]
47pub struct Dependencies {
48    pub host: Option<Vec<String>>,
49    pub make: Option<Vec<String>>,
50    pub run: Option<Vec<String>>,
51}
52
53/// The PkgInfo struct, that contains all info relevant to the package
54#[derive(Clone, Eq, Ord, PartialOrd, Hash, Default, Debug, PartialEq)]
55pub struct PkgInfo {
56    pub pkg_name: String,
57    pub version: String,
58    pub description: Option<String>,
59    pub homepage: String,
60    pub license: Option<Vec<String>>,
61    pub dependencies: Option<Dependencies>,
62    pub sha: String,
63    pub download_url: Option<String>,
64}
65
66pub(super) struct DownloadProgress<R> {
67    pub inner: R,
68    pub progress_bar: indicatif::ProgressBar,
69}
70
71impl<R: std::io::Read> std::io::Read for DownloadProgress<R> {
72    fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
73        self.inner.read(buf).map(|n| {
74            self.progress_bar.inc(n as u64);
75            n
76        })
77    }
78}
79
80#[derive(Debug, Deserialize)]
81pub(super) struct BuiltInDeps {
82    pub perl: Vec<String>,
83    pub ruby: Vec<String>,
84}
85
86#[derive(Debug, Deserialize)]
87pub(super) struct CorrectedVals {
88    pub licenses: Vec<CorrectedLicenses>,
89}
90
91#[derive(Debug, Deserialize)]
92pub(super) struct CorrectedLicenses {
93    pub is: String,
94    pub should: String,
95}
96
97#[derive(Debug, Deserialize)]
98pub(super) struct NativeDepType {
99    pub rust: Vec<NativeDeps>,
100}
101
102#[derive(Debug, Deserialize)]
103pub(super) struct NativeDeps {
104    pub name: String,
105    pub dep: String,
106}
107
108#[derive(Debug, Deserialize)]
109pub(super) struct TomlData {
110    pub builtin: BuiltInDeps,
111    pub licenses: Vec<CorrectedLicenses>,
112    pub native_deps: NativeDepType,
113}