Skip to content

Commit

Permalink
feat: macro ArgumentType
Browse files Browse the repository at this point in the history
  • Loading branch information
EqualMa committed May 10, 2023
1 parent 8f79c40 commit 995ac66
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ pub trait ProvideArgument {
) -> Out;
}

/// Don't try to remember the name, use [`ArgumentType`](crate::ArgumentType) instead.
pub struct Value<T>(PhantomData<T>, Invalid);
/// Don't try to remember the name, use [`ArgumentType`](crate::ArgumentType) instead.
pub struct ByRef<T: ?Sized>(PhantomData<T>, Invalid);
/// Don't try to remember the name, use [`ArgumentType`](crate::ArgumentType) instead.
pub struct ByMut<T: ?Sized>(PhantomData<T>, Invalid);

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ mod imp;

pub use imp::*;

/// ```
/// # use callable::{ArgumentType, ArgumentTypes};
/// # fn __(v:
/// (ArgumentType![u8], ArgumentType![&str], ArgumentType![&mut Vec<u8>])
/// # ) ->
/// // is exactly the same as
/// ArgumentTypes!(u8, &str, &mut Vec<u8>)
/// # { v }
/// ```
#[macro_export]
macro_rules! ArgumentType {
(&mut $t:ty) => { $crate::argument::ByMut<$t> };
(& $t:ty) => { $crate::argument::ByRef<$t> };
( $t:ty) => { $crate::argument::Value<$t> };
}

#[macro_export]
macro_rules! ArgumentTypes {
() => {
Expand Down

0 comments on commit 995ac66

Please sign in to comment.