Skip to main content

chaste_types/derivation/
patch.rs

1// SPDX-FileCopyrightText: 2025 The Chaste Authors
2// SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause
3
4use ssri::Integrity;
5
6use crate::error::Result;
7
8#[derive(Debug, Clone, PartialEq, Eq)]
9#[non_exhaustive]
10pub struct PackagePatch {
11    path: String,
12    integrity: Option<Integrity>,
13}
14
15impl PackagePatch {
16    pub fn path(&self) -> &str {
17        &self.path
18    }
19
20    /// Integrity of the patch file.
21    pub fn integrity(&self) -> Option<&Integrity> {
22        self.integrity.as_ref()
23    }
24}
25
26pub struct PackagePatchBuilder {
27    path: String,
28    integrity: Option<Integrity>,
29}
30
31impl PackagePatchBuilder {
32    pub fn new(path: String) -> Self {
33        Self {
34            path,
35            integrity: None,
36        }
37    }
38
39    pub fn integrity(&mut self, new_integrity: Integrity) {
40        self.integrity = Some(new_integrity);
41    }
42
43    pub fn build(self) -> Result<PackagePatch> {
44        Ok(PackagePatch {
45            path: self.path,
46            integrity: self.integrity,
47        })
48    }
49}