diff options
-rw-r--r-- | src/args.rs | 13 | ||||
-rw-r--r-- | src/tree.rs | 3 |
2 files changed, 11 insertions, 5 deletions
diff --git a/src/args.rs b/src/args.rs index 8647ea7..10b8fea 100644 --- a/src/args.rs +++ b/src/args.rs @@ -26,7 +26,14 @@ use crate::suggestion::SuggestionsBuilder; /// The parsing context of a command. pub struct CommandContext<'i, S, E>(::std::marker::PhantomData<(&'i str, S, E)>); -/// An argument parser. +/// An argument parser/validator. +/// +/// Note: Iosonism requires arguments to be `Send + Sync`, but for ease when +/// implementing generic argument types, those bounds are not reflected in this +/// trait. Nevertheless, Iosonism doesn't itself use threads, so a [workaround] +/// can be used if one needs non-`Send + Sync` argument types. +/// +/// [workaround]: https://users.rust-lang.org/t/how-to-check-send-at-runtime-similar-to-how-refcell-checks-borrowing-at-runtime/68269 /// /// # Type params /// @@ -86,7 +93,7 @@ pub trait ArgumentType<S, E> { } /// Wrapper around `ArgumentType`, but with `Any`. -pub(crate) trait ArgumentTypeAny<S, E> { +pub(crate) trait ArgumentTypeAny<S, E>: Send + Sync { /// Parses an argument of this type, returning the parsed argument. fn parse<'i>( &self, @@ -104,7 +111,7 @@ pub(crate) trait ArgumentTypeAny<S, E> { fn get_examples(&self) -> Cow<'static, [&str]>; } -impl<T: ArgumentType<S, E>, S, E> ArgumentTypeAny<S, E> for T { +impl<T: ArgumentType<S, E> + Send + Sync, S, E> ArgumentTypeAny<S, E> for T { fn parse<'i>( &self, reader: &mut Cursor<&'i str>, diff --git a/src/tree.rs b/src/tree.rs index daac8d3..71243be 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -3,7 +3,6 @@ // Licensed under the MIT license. // Documentation and comments licensed under CC BY-SA 4.0. -#![allow(dead_code, unused_imports)] // for now //! Command syntax tree. use ::std::borrow::Cow; @@ -75,7 +74,7 @@ impl<T, S, E> CommandNode<T, S, E> { } /// Creates a new argument node. - pub fn argument<A: ArgumentType<S, E> + 'static>( + pub fn argument<A: ArgumentType<S, E> + 'static + Send + Sync>( name: Cow<'static, str>, command: Option<Command<T, S, E>>, argument: A, |