mashin_core 0.1.4

The core of mashin, consumed by the runtime engine
Documentation
/* -------------------------------------------------------- *\
 *                                                          *
 *      ███╗░░░███╗░█████╗░░██████╗██╗░░██╗██╗███╗░░██╗     *
 *      ████╗░████║██╔══██╗██╔════╝██║░░██║██║████╗░██║     *
 *      ██╔████╔██║███████║╚█████╗░███████║██║██╔██╗██║     *
 *      ██║╚██╔╝██║██╔══██║░╚═══██╗██╔══██║██║██║╚████║     *
 *      ██║░╚═╝░██║██║░░██║██████╔╝██║░░██║██║██║░╚███║     *
 *      ╚═╝░░░░░╚═╝╚═╝░░╚═╝╚═════╝░╚═╝░░╚═╝╚═╝╚═╝░░╚══╝     *
 *                                         by Nutshimit     *
 * -------------------------------------------------------- *
 *                                                          *
 *   This file is dual-licensed as Apache-2.0 or GPL-3.0.   *
 *   see LICENSE for license details.                       *
 *                                                          *
\* ---------------------------------------------------------*/

use crate::{mashin_dir::MashinDir, EncryptedState, FileState, Result, StateHandler, StateInner};
use mashin_sdk::Urn;
use std::collections::BTreeSet;

pub enum BackendState {
	Local(FileState),
	Plugin(StateInner),
}

impl BackendState {
	pub fn new(mashin_dir: &MashinDir) -> Result<Self> {
		Ok(Self::Local(FileState::new(mashin_dir.state_folder_path())?))
	}
	pub fn save(&self, urn: &Urn, state: &EncryptedState) -> Result<()> {
		match self {
			BackendState::Local(local) => local.save(urn, state),
			BackendState::Plugin(_) => todo!(),
		}
	}

	pub fn get(&self, urn: &Urn) -> Result<Option<EncryptedState>> {
		match self {
			BackendState::Local(local) => local.get(urn),
			BackendState::Plugin(_) => todo!(),
		}
	}

	pub fn resources(&self) -> Result<BTreeSet<Urn>> {
		match self {
			BackendState::Local(local) => local.resources(),
			BackendState::Plugin(_) => todo!(),
		}
	}

	pub fn delete(&self, urn: &Urn) -> Result<()> {
		match self {
			BackendState::Local(local) => local.delete(urn),
			BackendState::Plugin(_) => todo!(),
		}
	}
}