From af12dccd5d42aaf7fd042f6c77f4cc743211ba3f Mon Sep 17 00:00:00 2001 From: John Doty Date: Fri, 23 Jun 2023 05:42:05 -0700 Subject: [PATCH] [oden-js] Functions up to 8 args --- oden-js/src/conversion/function.rs | 130 ++++++++++++++++++++++++++--- 1 file changed, 120 insertions(+), 10 deletions(-) diff --git a/oden-js/src/conversion/function.rs b/oden-js/src/conversion/function.rs index 8f5148d2..cd3e9878 100644 --- a/oden-js/src/conversion/function.rs +++ b/oden-js/src/conversion/function.rs @@ -48,11 +48,11 @@ where } } -impl RustFunction> for F +impl RustFunction> for FN where R: IntoRustFunctionResult, A: TryFromValue, - F: Fn(&ContextRef, A) -> R + Sized, + FN: Fn(&ContextRef, A) -> R + Sized, { fn argument_count() -> usize { 1 @@ -72,12 +72,12 @@ where } } -impl RustFunction> for F +impl RustFunction> for FN where R: IntoRustFunctionResult, A: TryFromValue, B: TryFromValue, - F: Fn(&ContextRef, A, B) -> R + Sized, + FN: Fn(&ContextRef, A, B) -> R + Sized, { fn argument_count() -> usize { 2 @@ -98,13 +98,13 @@ where } } -impl RustFunction> for F +impl RustFunction> for FN where R: IntoRustFunctionResult, A: TryFromValue, B: TryFromValue, C: TryFromValue, - F: Fn(&ContextRef, A, B, C) -> R + Sized, + FN: Fn(&ContextRef, A, B, C) -> R + Sized, { fn argument_count() -> usize { 3 @@ -126,14 +126,14 @@ where } } -impl RustFunction> for F +impl RustFunction> for FN where R: IntoRustFunctionResult, A: TryFromValue, B: TryFromValue, C: TryFromValue, D: TryFromValue, - F: Fn(&ContextRef, A, B, C, D) -> R + Sized, + FN: Fn(&ContextRef, A, B, C, D) -> R + Sized, { fn argument_count() -> usize { 4 @@ -156,7 +156,7 @@ where } } -impl RustFunction> for F +impl RustFunction> for FN where R: IntoRustFunctionResult, A: TryFromValue, @@ -164,7 +164,7 @@ where C: TryFromValue, D: TryFromValue, E: TryFromValue, - F: Fn(&ContextRef, A, B, C, D, E) -> R + Sized, + FN: Fn(&ContextRef, A, B, C, D, E) -> R + Sized, { fn argument_count() -> usize { 5 @@ -187,3 +187,113 @@ where res.into_res(context) } } + +impl RustFunction> for FN +where + R: IntoRustFunctionResult, + A: TryFromValue, + B: TryFromValue, + C: TryFromValue, + D: TryFromValue, + E: TryFromValue, + F: TryFromValue, + FN: Fn(&ContextRef, A, B, C, D, E, F) -> R + Sized, +{ + fn argument_count() -> usize { + 6 + } + + fn call(&self, context: &ContextRef, args: &[&ValueRef]) -> ValueResult { + if args.len() != Self::argument_count() { + return Err(Error::ArgumentCountMismatch { + expected: Self::argument_count(), + received: args.len(), + }); + } + + let va = A::try_from_value(args[0], &context)?; + let vb = B::try_from_value(args[1], &context)?; + let vc = C::try_from_value(args[2], &context)?; + let vd = D::try_from_value(args[3], &context)?; + let ve = E::try_from_value(args[4], &context)?; + let vf = F::try_from_value(args[4], &context)?; + let res = self(context, va, vb, vc, vd, ve, vf); + res.into_res(context) + } +} + +impl RustFunction> + for FN +where + R: IntoRustFunctionResult, + A: TryFromValue, + B: TryFromValue, + C: TryFromValue, + D: TryFromValue, + E: TryFromValue, + F: TryFromValue, + G: TryFromValue, + FN: Fn(&ContextRef, A, B, C, D, E, F, G) -> R + Sized, +{ + fn argument_count() -> usize { + 7 + } + + fn call(&self, context: &ContextRef, args: &[&ValueRef]) -> ValueResult { + if args.len() != Self::argument_count() { + return Err(Error::ArgumentCountMismatch { + expected: Self::argument_count(), + received: args.len(), + }); + } + + let va = A::try_from_value(args[0], &context)?; + let vb = B::try_from_value(args[1], &context)?; + let vc = C::try_from_value(args[2], &context)?; + let vd = D::try_from_value(args[3], &context)?; + let ve = E::try_from_value(args[4], &context)?; + let vf = F::try_from_value(args[4], &context)?; + let vg = G::try_from_value(args[4], &context)?; + let res = self(context, va, vb, vc, vd, ve, vf, vg); + res.into_res(context) + } +} + +impl + RustFunction> for FN +where + R: IntoRustFunctionResult, + A: TryFromValue, + B: TryFromValue, + C: TryFromValue, + D: TryFromValue, + E: TryFromValue, + F: TryFromValue, + G: TryFromValue, + H: TryFromValue, + FN: Fn(&ContextRef, A, B, C, D, E, F, G, H) -> R + Sized, +{ + fn argument_count() -> usize { + 8 + } + + fn call(&self, context: &ContextRef, args: &[&ValueRef]) -> ValueResult { + if args.len() != Self::argument_count() { + return Err(Error::ArgumentCountMismatch { + expected: Self::argument_count(), + received: args.len(), + }); + } + + let va = A::try_from_value(args[0], &context)?; + let vb = B::try_from_value(args[1], &context)?; + let vc = C::try_from_value(args[2], &context)?; + let vd = D::try_from_value(args[3], &context)?; + let ve = E::try_from_value(args[4], &context)?; + let vf = F::try_from_value(args[4], &context)?; + let vg = G::try_from_value(args[4], &context)?; + let vh = H::try_from_value(args[4], &context)?; + let res = self(context, va, vb, vc, vd, ve, vf, vg, vh); + res.into_res(context) + } +}