From 70137e6614843c42dd9ad32abf00e5fc7da7662f Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sun, 5 Dec 2021 00:11:33 -0300 Subject: Add more Send + Sync --- src/args.rs | 13 ++++++++++--- src/tree.rs | 3 +-- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src') 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 { } /// Wrapper around `ArgumentType`, but with `Any`. -pub(crate) trait ArgumentTypeAny { +pub(crate) trait ArgumentTypeAny: Send + Sync { /// Parses an argument of this type, returning the parsed argument. fn parse<'i>( &self, @@ -104,7 +111,7 @@ pub(crate) trait ArgumentTypeAny { fn get_examples(&self) -> Cow<'static, [&str]>; } -impl, S, E> ArgumentTypeAny for T { +impl + Send + Sync, S, E> ArgumentTypeAny 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 CommandNode { } /// Creates a new argument node. - pub fn argument + 'static>( + pub fn argument + 'static + Send + Sync>( name: Cow<'static, str>, command: Option>, argument: A, -- cgit 1.4.1