plexor-core 0.1.0-alpha.2

Core library for the rust implementation of the Plexo distributed system architecture, providing the fundamental Plexus, Neuron, Codec, and Axon abstractions.
Documentation
// Copyright 2025 Alecks Gates
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

//! Utility functions for the plexor-core crate

///
/// This function takes a generic type T and returns the last part of its type name
/// by splitting on "::" and taking the last element. This is useful for getting
/// just the struct name without the full module path.
///
/// # Examples
///
/// ```
/// use plexor_core::utils::struct_name_of_type;
///
/// struct MyStruct;
/// assert_eq!(struct_name_of_type::<MyStruct>(), "MyStruct");
/// ```
#[must_use]
pub fn struct_name_of_type<T: ?Sized>() -> &'static str {
    let type_name = std::any::type_name::<T>();
    type_name.split("::").last().unwrap()
}

#[cfg(test)]
mod tests {
    use super::*;

    struct TestStruct;

    #[test]
    fn test_struct_name_of_type() {
        assert_eq!(struct_name_of_type::<TestStruct>(), "TestStruct");
        assert_eq!(struct_name_of_type::<String>(), "String");
        assert_eq!(struct_name_of_type::<Vec<i32>>(), "Vec<i32>");
    }
}