specta 2.0.0-rc.9

Easily export your Rust types to other languages
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::{DataType, Type, TypeMap};

/// Implemented by types that can be used as an argument in a function annotated with
/// [`specta`](crate::specta).
pub trait FunctionArg {
    /// Gets the type of an argument as a [`DataType`].
    ///
    /// Some argument types should be ignored (eg. when doing dependency injection),
    /// so the value is optional.
    fn to_datatype(type_map: &mut TypeMap) -> Option<DataType>;
}

impl<T: Type> FunctionArg for T {
    fn to_datatype(type_map: &mut TypeMap) -> Option<DataType> {
        Some(T::reference(type_map, &[]).inner)
    }
}