wasmer_package/package/
strictness.rs1use std::{fmt::Debug, path::Path};
2
3use anyhow::Error;
4
5use super::ManifestError;
6
7#[derive(Debug, Default, Copy, Clone, PartialEq)]
14pub enum Strictness {
15 #[default]
17 Lossy,
18 Strict,
20}
21
22impl Strictness {
23 pub(crate) fn is_strict(self) -> bool {
24 matches!(self, Strictness::Strict)
25 }
26
27 pub(crate) fn on_error(&self, _path: &Path, error: Error) -> Result<(), Error> {
28 match self {
29 Strictness::Lossy => Ok(()),
30 Strictness::Strict => Err(error),
31 }
32 }
33
34 pub(crate) fn outside_base_directory(
35 &self,
36 path: &Path,
37 base_dir: &Path,
38 ) -> Result<(), ManifestError> {
39 match self {
40 Strictness::Lossy => todo!(),
41 Strictness::Strict => Err(ManifestError::OutsideBaseDirectory {
42 path: path.to_path_buf(),
43 base_dir: base_dir.to_path_buf(),
44 }),
45 }
46 }
47
48 pub(crate) fn missing_file(&self, path: &Path, base_dir: &Path) -> Result<(), ManifestError> {
49 match self {
50 Strictness::Lossy => Ok(()),
51 Strictness::Strict => Err(ManifestError::MissingFile {
52 path: path.to_path_buf(),
53 base_dir: base_dir.to_path_buf(),
54 }),
55 }
56 }
57}