aleym_core 0.1.0-alpha.1

Extensible news aggregation and knowledge-base engine (Core Library Component of Aleym)
Documentation
#[cfg(feature = "net_interface_clear")]
mod clear;
#[cfg(feature = "net_interface_tor")]
mod tor;

#[cfg(feature = "net_interface_clear")]
pub(super) use clear::ClearInterface;
#[cfg(feature = "net_interface_tor")]
pub(super) use tor::TorInterface;

use crate::net::NetworkError;

/// # Network Interface Type
#[derive(Debug, PartialEq, Eq, Clone, Copy, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[repr(i8)]
pub enum Type {
	/// # Placeholder for Testing
	#[cfg(any(test, not(any(feature = "net_interface_clear", feature = "net_interface_tor"))))]
	TestPlaceholder = 0,
	/// # Clear (Clearnet)
	/// Standard internet interface.
	#[cfg(feature = "net_interface_clear")]
	Clear = 1,
	/// # Tor (Onion)
	/// Anonymous-routing interface using the Tor network.
	#[cfg(feature = "net_interface_tor")]
	Tor = 2,
}

impl TryFrom<i8> for Type {
	type Error = NetworkError;

	fn try_from(value: i8) -> Result<Self, Self::Error> {
		match value {
			#[cfg(any(test, not(any(feature = "net_interface_clear", feature = "net_interface_tor"))))]
			0 => Ok(Self::TestPlaceholder),
			#[cfg(feature = "net_interface_clear")]
			1 => Ok(Self::Clear),
			#[cfg(feature = "net_interface_tor")]
			2 => Ok(Self::Tor),
			value => Err(NetworkError::UnsupportedNetworkInterfaceIdentifier(value)),
		}
	}
}

impl From<Type> for sea_orm::Value {
	fn from(value: Type) -> Self {
		sea_orm::Value::TinyInt(Some(value as i8))
	}
}