dataport 0.1.0

Port abstractions for data types
Documentation
// Copyright © 2026 Stephan Kunz
//! Error implementation.

use core::{
	num::{ParseFloatError, ParseIntError},
	str::ParseBoolError,
};

use thiserror::Error;

use crate::ConstString;

/// Port errors.
#[derive(Error, Debug, PartialEq)]
pub enum Error {
	/// Port already in the collection.
	#[error("a port with that name is already in the collection")]
	AlreadyExists,
	/// Port has other data type then expected.
	#[error("port has a different data type then expected")]
	DataType,
	/// Conversion [`FromStr`] failed.
	#[error("could not convert port value from 'str'")]
	FromStr,
	/// A ports value is currently locked.
	#[error("port is currently locked")]
	IsLocked,
	/// Port cannot be found.
	#[error("port '{name}' could not be found in the collection")]
	NotFound {
		/// Name of the port.
		name: ConstString,
	},
	/// No value set for a port.
	#[error("no value set for port")]
	NoValueSet,
	/// The port 'other' cannot be found.
	#[error("port '{name}' could not be found in 'other' collection")]
	OtherNotFound {
		/// Name of the port.
		name: ConstString,
	},
	/// Port value could not be parsed.
	#[error("value for port could not be parsed")]
	ParseValue,
	/// Port has not the needed type.
	#[error("port has an incompatible type")]
	PortType,
	/// Port has a different type than 'value'.
	#[error("port '{port}' returns '{value}' with a different type")]
	ReturnTypeMismatch { port: ConstString, value: ConstString },
}

impl From<ParseBoolError> for Error {
	fn from(_value: ParseBoolError) -> Self {
		Self::ParseValue
	}
}

impl From<ParseFloatError> for Error {
	fn from(_value: ParseFloatError) -> Self {
		Self::ParseValue
	}
}

impl From<ParseIntError> for Error {
	fn from(_value: ParseIntError) -> Self {
		Self::ParseValue
	}
}