feagi_evolutionary/
types.rs

1// Copyright 2025 Neuraville Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4/*!
5Core types and error handling for FEAGI Evolution.
6
7Copyright 2025 Neuraville Inc.
8Licensed under the Apache License, Version 2.0
9*/
10
11use thiserror::Error;
12
13/// Result type for evolution operations
14pub type EvoResult<T> = Result<T, EvoError>;
15
16/// Error types for evolution operations
17#[derive(Error, Debug)]
18pub enum EvoError {
19    #[error("Invalid genome: {0}")]
20    InvalidGenome(String),
21
22    #[error("Genome validation failed: {0}")]
23    ValidationFailed(String),
24
25    #[error("JSON parsing error: {0}")]
26    JsonError(String),
27
28    #[error("I/O error: {0}")]
29    IoError(String),
30
31    #[error("Internal error: {0}")]
32    Internal(String),
33
34    #[error("Invalid cortical area: {0}")]
35    InvalidArea(String),
36
37    #[error("Invalid brain region: {0}")]
38    InvalidRegion(String),
39}
40
41// Convert from serde_json::Error
42impl From<serde_json::Error> for EvoError {
43    fn from(err: serde_json::Error) -> Self {
44        EvoError::JsonError(err.to_string())
45    }
46}
47
48// Convert from std::io::Error
49impl From<std::io::Error> for EvoError {
50    fn from(err: std::io::Error) -> Self {
51        EvoError::IoError(err.to_string())
52    }
53}
54
55// Convert from FeagiDataError
56impl From<feagi_structures::FeagiDataError> for EvoError {
57    fn from(err: feagi_structures::FeagiDataError) -> Self {
58        match &err {
59            feagi_structures::FeagiDataError::BadParameters(msg) => {
60                EvoError::InvalidArea(msg.clone())
61            }
62            _ => EvoError::Internal(err.to_string()),
63        }
64    }
65}