Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbbd1c3
commit 2ae7766
Showing
3 changed files
with
38 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,19 @@ | ||
mod private { | ||
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<TMarker> { | ||
/// Gets the type of an argument as a [`DataType`]. | ||
/// | ||
/// Some argument types should be ignored (eg Tauri command State), | ||
/// so the value is optional. | ||
fn to_datatype(type_map: &mut TypeMap) -> Option<DataType>; | ||
} | ||
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<TMarker> { | ||
/// Gets the type of an argument as a [`DataType`]. | ||
/// | ||
/// Some argument types should be ignored (eg Tauri command State), | ||
/// so the value is optional. | ||
fn to_datatype(type_map: &mut TypeMap) -> Option<DataType>; | ||
} | ||
|
||
pub enum FunctionArgMarker {} | ||
pub enum FunctionArgMarker {} | ||
|
||
impl<T: Type> FunctionArg<FunctionArgMarker> for T { | ||
fn to_datatype(type_map: &mut TypeMap) -> Option<DataType> { | ||
Some(T::reference(type_map, &[]).inner) | ||
} | ||
impl<T: Type> FunctionArg<FunctionArgMarker> for T { | ||
fn to_datatype(type_map: &mut TypeMap) -> Option<DataType> { | ||
Some(T::reference(type_map, &[]).inner) | ||
} | ||
|
||
#[cfg(feature = "tauri")] | ||
const _: () = { | ||
pub enum FunctionArgTauriMarker {} | ||
|
||
impl<R: tauri::Runtime> FunctionArg<FunctionArgTauriMarker> for tauri::Window<R> { | ||
fn to_datatype(_: &mut TypeMap) -> Option<DataType> { | ||
None | ||
} | ||
} | ||
|
||
impl<'r, T: Send + Sync + 'static> FunctionArg<FunctionArgTauriMarker> for tauri::State<'r, T> { | ||
fn to_datatype(_: &mut TypeMap) -> Option<DataType> { | ||
None | ||
} | ||
} | ||
|
||
impl<R: tauri::Runtime> FunctionArg<FunctionArgTauriMarker> for tauri::AppHandle<R> { | ||
fn to_datatype(_: &mut TypeMap) -> Option<DataType> { | ||
None | ||
} | ||
} | ||
}; | ||
} | ||
|
||
pub(crate) use private::FunctionArg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,28 @@ | ||
mod private { | ||
use std::future::Future; | ||
use std::future::Future; | ||
|
||
use crate::{DataType, Type, TypeMap}; | ||
use crate::{DataType, Type, TypeMap}; | ||
|
||
/// Implemented by types that can be returned from a function annotated with | ||
/// [`specta`](crate::specta). | ||
pub trait FunctionResult<TMarker> { | ||
/// Gets the type of the result as a [`DataType`]. | ||
fn to_datatype(type_map: &mut TypeMap) -> DataType; | ||
} | ||
/// Implemented by types that can be returned from a function annotated with | ||
/// [`specta`](crate::specta). | ||
pub trait FunctionResult<TMarker> { | ||
/// Gets the type of the result as a [`DataType`]. | ||
fn to_datatype(type_map: &mut TypeMap) -> DataType; | ||
} | ||
|
||
pub enum FunctionResultMarker {} | ||
impl<T: Type> FunctionResult<FunctionResultMarker> for T { | ||
fn to_datatype(type_map: &mut TypeMap) -> DataType { | ||
T::reference(type_map, &[]).inner | ||
} | ||
pub enum FunctionResultMarker {} | ||
impl<T: Type> FunctionResult<FunctionResultMarker> for T { | ||
fn to_datatype(type_map: &mut TypeMap) -> DataType { | ||
T::reference(type_map, &[]).inner | ||
} | ||
} | ||
|
||
pub enum FunctionResultFutureMarker {} | ||
impl<F> FunctionResult<FunctionResultFutureMarker> for F | ||
where | ||
F: Future, | ||
F::Output: Type, | ||
{ | ||
fn to_datatype(type_map: &mut TypeMap) -> DataType { | ||
F::Output::reference(type_map, &[]).inner | ||
} | ||
pub enum FunctionResultFutureMarker {} | ||
impl<F> FunctionResult<FunctionResultFutureMarker> for F | ||
where | ||
F: Future, | ||
F::Output: Type, | ||
{ | ||
fn to_datatype(type_map: &mut TypeMap) -> DataType { | ||
F::Output::reference(type_map, &[]).inner | ||
} | ||
} | ||
|
||
pub(crate) use private::FunctionResult; |