diff --git a/crates/rune/src/compile/context.rs b/crates/rune/src/compile/context.rs index 67fe92a29..fac486440 100644 --- a/crates/rune/src/compile/context.rs +++ b/crates/rune/src/compile/context.rs @@ -862,7 +862,7 @@ impl Context { } /// Add a piece of internal tuple meta. - fn add_internal_tuple( + fn add_internal_tuple( &mut self, module: &Module, enum_item: Option<(Hash, usize)>, @@ -872,7 +872,7 @@ impl Context { docs: Docs, ) -> Result<(), ContextError> where - C: Function, + C: Function, C::Return: TypeOf, { let type_hash = ::type_hash(); diff --git a/crates/rune/src/module.rs b/crates/rune/src/module.rs index 9a002bca6..9ccb18ee4 100644 --- a/crates/rune/src/module.rs +++ b/crates/rune/src/module.rs @@ -70,9 +70,9 @@ impl InternalEnum { } /// Register a new variant. - fn variant(&mut self, name: &'static str, type_check: TypeCheck, constructor: C) + fn variant(&mut self, name: &'static str, type_check: TypeCheck, constructor: C) where - C: Function, + C: Function, { let constructor: Arc = Arc::new(move |stack, args| constructor.fn_call(stack, args)); diff --git a/crates/rune/src/module/function_meta.rs b/crates/rune/src/module/function_meta.rs index 62b016044..d8226869c 100644 --- a/crates/rune/src/module/function_meta.rs +++ b/crates/rune/src/module/function_meta.rs @@ -56,45 +56,45 @@ pub struct FunctionData { impl FunctionData { #[inline] - pub(crate) fn new(name: N, f: Func) -> Self + pub(crate) fn new(name: N, f: F) -> Self where - Func: Function, - Func::Return: MaybeTypeOf, + F: Function, + F::Return: MaybeTypeOf, N: IntoIterator, N::Item: IntoComponent, - Args: IterFunctionArgs, + A: IterFunctionArgs, { - let mut argument_types = Vec::with_capacity(Args::len()); - Args::iter_args(|ty| argument_types.push(ty)); + let mut argument_types = Vec::with_capacity(A::len()); + A::iter_args(|ty| argument_types.push(ty)); Self { is_async: false, name: ItemBuf::with_item(name), handler: Arc::new(move |stack, args| f.fn_call(stack, args)), - args: Some(Func::args()), - return_type: Func::Return::maybe_type_of(), + args: Some(F::args()), + return_type: F::Return::maybe_type_of(), argument_types: argument_types.into(), } } #[inline] - pub(crate) fn new_async(name: N, f: Func) -> Self + pub(crate) fn new_async(name: N, f: F) -> Self where - Func: AsyncFunction, - Func::Output: MaybeTypeOf, + F: AsyncFunction, + F::Output: MaybeTypeOf, N: IntoIterator, N::Item: IntoComponent, - Args: IterFunctionArgs, + A: IterFunctionArgs, { - let mut argument_types = Vec::with_capacity(Args::len()); - Args::iter_args(|ty| argument_types.push(ty)); + let mut argument_types = Vec::with_capacity(A::len()); + A::iter_args(|ty| argument_types.push(ty)); Self { is_async: true, name: ItemBuf::with_item(name), handler: Arc::new(move |stack, args| f.fn_call(stack, args)), - args: Some(Func::args()), - return_type: Func::Output::maybe_type_of(), + args: Some(F::args()), + return_type: F::Output::maybe_type_of(), argument_types: argument_types.into(), } } @@ -109,9 +109,9 @@ pub struct FunctionMacroData { impl FunctionMacroData { #[inline] - pub(crate) fn new(name: N, f: Func) -> Self + pub(crate) fn new(name: N, f: F) -> Self where - Func: 'static + F: 'static + Send + Sync + Fn(&mut MacroContext<'_>, &TokenStream) -> compile::Result, @@ -245,43 +245,43 @@ pub struct AssociatedFunctionData { impl AssociatedFunctionData { #[inline] - pub(crate) fn new(name: AssociatedFunctionName, f: Func) -> Self + pub(crate) fn new(name: AssociatedFunctionName, f: F) -> Self where - Func: InstFn, - Func::Return: MaybeTypeOf, - Args: IterFunctionArgs, + F: InstFn, + F::Return: MaybeTypeOf, + A: IterFunctionArgs, { - let mut argument_types = Vec::with_capacity(Args::len()); - Args::iter_args(|ty| argument_types.push(ty)); + let mut argument_types = Vec::with_capacity(A::len()); + A::iter_args(|ty| argument_types.push(ty)); Self { name, handler: Arc::new(move |stack, args| f.fn_call(stack, args)), - ty: Func::ty(), + ty: F::ty(), is_async: false, - args: Some(Func::args()), - return_type: Func::Return::maybe_type_of(), + args: Some(F::args()), + return_type: F::Return::maybe_type_of(), argument_types: argument_types.into(), } } #[inline] - pub(crate) fn new_async(name: AssociatedFunctionName, f: Func) -> Self + pub(crate) fn new_async(name: AssociatedFunctionName, f: F) -> Self where - Func: AsyncInstFn, - Func::Output: MaybeTypeOf, - Args: IterFunctionArgs, + F: AsyncInstFn, + F::Output: MaybeTypeOf, + A: IterFunctionArgs, { - let mut argument_types = Vec::with_capacity(Args::len()); - Args::iter_args(|ty| argument_types.push(ty)); + let mut argument_types = Vec::with_capacity(A::len()); + A::iter_args(|ty| argument_types.push(ty)); Self { name, handler: Arc::new(move |stack, args| f.fn_call(stack, args)), - ty: Func::ty(), + ty: F::ty(), is_async: true, - args: Some(Func::args()), - return_type: ::Output::maybe_type_of(), + args: Some(F::args()), + return_type: ::Output::maybe_type_of(), argument_types: argument_types.into(), } } @@ -312,27 +312,27 @@ pub enum FunctionMetaKind { impl FunctionMetaKind { #[doc(hidden)] #[inline] - pub fn function(name: N, f: Func) -> Self + pub fn function(name: N, f: F) -> Self where N: IntoIterator, N::Item: IntoComponent, - Func: Function, - Func::Return: MaybeTypeOf, - Args: IterFunctionArgs, + F: Function, + F::Return: MaybeTypeOf, + A: IterFunctionArgs, { Self::Function(FunctionData::new(name, f)) } #[doc(hidden)] #[inline] - pub fn function_with(name: N, f: Func) -> Self + pub fn function_with(name: N, f: F) -> Self where T: Named, N: IntoIterator, N::Item: IntoComponent, - Func: Function, - Func::Return: MaybeTypeOf, - Args: IterFunctionArgs, + F: Function, + F::Return: MaybeTypeOf, + A: IterFunctionArgs, { let name = [IntoComponent::into_component(T::BASE_NAME)] .into_iter() @@ -342,27 +342,27 @@ impl FunctionMetaKind { #[doc(hidden)] #[inline] - pub fn async_function(name: N, f: Func) -> Self + pub fn async_function(name: N, f: F) -> Self where N: IntoIterator, N::Item: IntoComponent, - Func: AsyncFunction, - Func::Output: MaybeTypeOf, - Args: IterFunctionArgs, + F: AsyncFunction, + F::Output: MaybeTypeOf, + A: IterFunctionArgs, { Self::Function(FunctionData::new_async(name, f)) } #[doc(hidden)] #[inline] - pub fn async_function_with(name: N, f: Func) -> Self + pub fn async_function_with(name: N, f: F) -> Self where T: Named, N: IntoIterator, N::Item: IntoComponent, - Func: AsyncFunction, - Func::Output: MaybeTypeOf, - Args: IterFunctionArgs, + F: AsyncFunction, + F::Output: MaybeTypeOf, + A: IterFunctionArgs, { let name = [IntoComponent::into_component(T::BASE_NAME)] .into_iter() @@ -372,24 +372,24 @@ impl FunctionMetaKind { #[doc(hidden)] #[inline] - pub fn instance(name: N, f: Func) -> Self + pub fn instance(name: N, f: F) -> Self where N: ToInstance, - Func: InstFn, - Func::Return: MaybeTypeOf, - Args: IterFunctionArgs, + F: InstFn, + F::Return: MaybeTypeOf, + A: IterFunctionArgs, { Self::AssociatedFunction(AssociatedFunctionData::new(name.to_instance(), f)) } #[doc(hidden)] #[inline] - pub fn async_instance(name: N, f: Func) -> Self + pub fn async_instance(name: N, f: F) -> Self where N: ToInstance, - Func: AsyncInstFn, - Func::Output: MaybeTypeOf, - Args: IterFunctionArgs, + F: AsyncInstFn, + F::Output: MaybeTypeOf, + A: IterFunctionArgs, { Self::AssociatedFunction(AssociatedFunctionData::new_async(name.to_instance(), f)) } @@ -409,9 +409,9 @@ pub enum MacroMetaKind { impl MacroMetaKind { #[doc(hidden)] #[inline] - pub fn function(name: N, f: Func) -> Self + pub fn function(name: N, f: F) -> Self where - Func: 'static + F: 'static + Send + Sync + Fn(&mut MacroContext<'_>, &TokenStream) -> compile::Result, diff --git a/crates/rune/src/module/function_traits.rs b/crates/rune/src/module/function_traits.rs index 51979889a..7e3b5eef6 100644 --- a/crates/rune/src/module/function_traits.rs +++ b/crates/rune/src/module/function_traits.rs @@ -1,7 +1,7 @@ -use core::future; +use core::future::Future; use crate::runtime::{ - Future, Stack, ToValue, TypeInfo, TypeOf, UnsafeFromValue, VmErrorKind, VmResult, + self, Stack, ToValue, TypeInfo, TypeOf, UnsafeFromValue, VmErrorKind, VmResult, }; use crate::Hash; @@ -62,7 +62,7 @@ pub struct AssocType { /// Trait used to provide the [function][crate::module::Module::function] /// function. -pub trait Function: 'static + Send + Sync { +pub trait Function: 'static + Send + Sync { /// The return type of the function. #[doc(hidden)] type Return; @@ -78,10 +78,10 @@ pub trait Function: 'static + Send + Sync { /// Trait used to provide the /// [async_function][crate::module::Module::async_function] function. -pub trait AsyncFunction: 'static + Send + Sync { +pub trait AsyncFunction: 'static + Send + Sync { /// The return type of the function. #[doc(hidden)] - type Return: future::Future; + type Return: Future; /// The output produces by the future. #[doc(hidden)] @@ -98,7 +98,7 @@ pub trait AsyncFunction: 'static + Send + Sync { /// Trait used to provide the [inst_fn][crate::module::Module::inst_fn] /// function. -pub trait InstFn: 'static + Send + Sync { +pub trait InstFn: 'static + Send + Sync { /// The type of the instance. #[doc(hidden)] type Instance; @@ -123,14 +123,14 @@ pub trait InstFn: 'static + Send + Sync { /// Trait used to provide the /// [async_inst_fn][crate::module::Module::async_inst_fn] function. -pub trait AsyncInstFn: 'static + Send + Sync { +pub trait AsyncInstFn: 'static + Send + Sync { /// The type of the instance. #[doc(hidden)] type Instance; /// The return type of the function. #[doc(hidden)] - type Return: future::Future; + type Return: Future; /// The output value of the async function. #[doc(hidden)] @@ -152,13 +152,13 @@ pub trait AsyncInstFn: 'static + Send + Sync { macro_rules! impl_register { ($count:expr $(, $ty:ident $var:ident $num:expr)*) => { - impl Function<($($ty,)*)> for Func + impl Function<($($ty,)*)> for Fu where - Func: 'static + Send + Sync + Fn($($ty,)*) -> Return, - Return: ToValue, + Fu: 'static + Send + Sync + Fn($($ty,)*) -> Re, + Re: ToValue, $($ty: UnsafeFromValue,)* { - type Return = Return; + type Return = Re; fn args() -> usize { $count @@ -187,15 +187,15 @@ macro_rules! impl_register { } } - impl AsyncFunction<($($ty,)*)> for Func + impl AsyncFunction<($($ty,)*)> for Fu where - Func: 'static + Send + Sync + Fn($($ty,)*) -> Return, - Return: 'static + future::Future, - Return::Output: ToValue, + Fu: 'static + Send + Sync + Fn($($ty,)*) -> Re, + Re: 'static + Future, + Re::Output: ToValue, $($ty: 'static + UnsafeFromValue,)* { - type Return = Return; - type Output = Return::Output; + type Return = Re; + type Output = Re::Output; fn args() -> usize { $count @@ -214,7 +214,7 @@ macro_rules! impl_register { unsafe_vars!($count, $($ty, $var, $num,)*); let fut = self($(<$ty>::unsafe_coerce($var.0),)*); - Future::new(async move { + runtime::Future::new(async move { let output = fut.await; drop_stack_guards!($($var),*); let value = vm_try!(output.to_value()); @@ -228,15 +228,15 @@ macro_rules! impl_register { } } - impl InstFn<(Instance, $($ty,)*)> for Func + impl InstFn<(Instance, $($ty,)*)> for Fu where - Func: 'static + Send + Sync + Fn(Instance $(, $ty)*) -> Return, - Return: ToValue, + Fu: 'static + Send + Sync + Fn(Instance $(, $ty)*) -> Re, + Re: ToValue, Instance: UnsafeFromValue + TypeOf, $($ty: UnsafeFromValue,)* { type Instance = Instance; - type Return = Return; + type Return = Re; fn args() -> usize { $count + 1 @@ -272,17 +272,17 @@ macro_rules! impl_register { } } - impl AsyncInstFn<(Instance, $($ty,)*)> for Func + impl AsyncInstFn<(Instance, $($ty,)*)> for Fu where - Func: 'static + Send + Sync + Fn(Instance $(, $ty)*) -> Return, - Return: 'static + future::Future, - Return::Output: ToValue, + Fu: 'static + Send + Sync + Fn(Instance $(, $ty)*) -> Re, + Re: 'static + Future, + Re::Output: ToValue, Instance: UnsafeFromValue + TypeOf, $($ty: UnsafeFromValue,)* { type Instance = Instance; - type Return = Return; - type Output = Return::Output; + type Return = Re; + type Output = Re::Output; fn args() -> usize { $count + 1 @@ -308,7 +308,7 @@ macro_rules! impl_register { unsafe_inst_vars!(inst, $count, $($ty, $var, $num,)*); let fut = self(Instance::unsafe_coerce(inst.0), $(<$ty>::unsafe_coerce($var.0),)*); - Future::new(async move { + runtime::Future::new(async move { let output = fut.await; drop_stack_guards!(inst, $($var),*); let value = vm_try!(output.to_value());