Struct shades::FunHandle [−][src]
An opaque function handle, used to call user-defined functions.
Function handles are created with the ShaderBuilder::fun
function, introducing new functions in the EDSL. You
can then call the functions in the context of generating new expressions, returning them or creating variables.
Injecting a function call in the EDSL is done via two current mechanisms:
- Either call the
FunHandle::call
method:- It is a function without argument if the represented function doesn’t have any argument.
- It is a unary function if the represented function has a single argument.
- It takes a tuple encapsulating the arguments for a n-ary represented function.
- On nightly only, you can enable the
fun-call
feature-gate and calling the function will do the same thing asFunHandle::call
. However, because of how the variousFnOnce
,FnMut
andFn
traits are made, functions taking several arguments take them as separate arguments as if it was a regular Rust function (they don’t take a tuple as with theFunHandle::call
method).
Examples
A unary function squaring its argument, the regular way:
use shades::{Expr, FunHandle, Scope, lit, vec2}; let square = s.fun(|s: &mut Scope<Expr<i32>>, a: Expr<i32>| { &a * &a }); s.main_fun(|s: &mut Scope<()>| { // call square with 3 and bind the result to a variable let squared = s.var(square.call(lit!(3))); })
The same function but with the fun-call
feature-gate enabled:
use shades::{Expr, Scope, lit}; let square = s.fun(|s: &mut Scope<Expr<i32>>, a: Expr<i32>| { &a * &a }); s.main_fun(|s: &mut Scope<()>| { // call square with 3 and bind the result to a variable let squared = s.var(square(lit!(3))); })
A function taking two 3D vectors and a floating scalar and returning their linear interpolation, called with three arguments:
use shades::{Expr, Mix as _, Scope, V3, lit, vec3}; let lerp = s.fun(|s: &mut Scope<Expr<V3<f32>>>, a: Expr<V3<f32>>, b: Expr<V3<f32>>, t: Expr<f32>| { a.mix(b, t) }); s.main_fun(|s: &mut Scope<()>| { let a = vec3!(0., 0., 0.); let b = vec3!(1., 1., 1.); // call lerp here and bind it to a local variable let result = s.var(lerp(a, b, lit!(0.75))); })
Implementations
impl<R> FunHandle<Expr<R>, ()>
[src]
pub fn call(&self) -> Expr<R>
[src]
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
impl<R, A> FunHandle<Expr<R>, Expr<A>>
[src]
pub fn call(&self, a: Expr<A>) -> Expr<R>
[src]
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
impl<R, A, P> FunHandle<Expr<R>, (Expr<A>, Expr<P>)>
[src]
pub fn call(&self, a: Expr<A>, p: Expr<P>) -> Expr<R>
[src]
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
impl<R, A, O, P> FunHandle<Expr<R>, (Expr<A>, Expr<O>, Expr<P>)>
[src]
pub fn call(&self, a: Expr<A>, o: Expr<O>, p: Expr<P>) -> Expr<R>
[src]
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
impl<R, A, N, O, P> FunHandle<Expr<R>, (Expr<A>, Expr<N>, Expr<O>, Expr<P>)>
[src]
pub fn call(&self, a: Expr<A>, n: Expr<N>, o: Expr<O>, p: Expr<P>) -> Expr<R>
[src]
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
impl<R, A, M, N, O, P> FunHandle<Expr<R>, (Expr<A>, Expr<M>, Expr<N>, Expr<O>, Expr<P>)>
[src]
pub fn call(
&self,
a: Expr<A>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
[src]
&self,
a: Expr<A>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
impl<R, A, L, M, N, O, P> FunHandle<Expr<R>, (Expr<A>, Expr<L>, Expr<M>, Expr<N>, Expr<O>, Expr<P>)>
[src]
pub fn call(
&self,
a: Expr<A>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
[src]
&self,
a: Expr<A>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
impl<R, A, K, L, M, N, O, P> FunHandle<Expr<R>, (Expr<A>, Expr<K>, Expr<L>, Expr<M>, Expr<N>, Expr<O>, Expr<P>)>
[src]
pub fn call(
&self,
a: Expr<A>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
[src]
&self,
a: Expr<A>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
impl<R, A, J, K, L, M, N, O, P> FunHandle<Expr<R>, (Expr<A>, Expr<J>, Expr<K>, Expr<L>, Expr<M>, Expr<N>, Expr<O>, Expr<P>)>
[src]
pub fn call(
&self,
a: Expr<A>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
[src]
&self,
a: Expr<A>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
impl<R, A, I, J, K, L, M, N, O, P> FunHandle<Expr<R>, (Expr<A>, Expr<I>, Expr<J>, Expr<K>, Expr<L>, Expr<M>, Expr<N>, Expr<O>, Expr<P>)>
[src]
pub fn call(
&self,
a: Expr<A>,
i: Expr<I>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
[src]
&self,
a: Expr<A>,
i: Expr<I>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
impl<R, A, H, I, J, K, L, M, N, O, P> FunHandle<Expr<R>, (Expr<A>, Expr<H>, Expr<I>, Expr<J>, Expr<K>, Expr<L>, Expr<M>, Expr<N>, Expr<O>, Expr<P>)>
[src]
pub fn call(
&self,
a: Expr<A>,
h: Expr<H>,
i: Expr<I>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
[src]
&self,
a: Expr<A>,
h: Expr<H>,
i: Expr<I>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
impl<R, A, G, H, I, J, K, L, M, N, O, P> FunHandle<Expr<R>, (Expr<A>, Expr<G>, Expr<H>, Expr<I>, Expr<J>, Expr<K>, Expr<L>, Expr<M>, Expr<N>, Expr<O>, Expr<P>)>
[src]
pub fn call(
&self,
a: Expr<A>,
g: Expr<G>,
h: Expr<H>,
i: Expr<I>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
[src]
&self,
a: Expr<A>,
g: Expr<G>,
h: Expr<H>,
i: Expr<I>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
impl<R, A, F, G, H, I, J, K, L, M, N, O, P> FunHandle<Expr<R>, (Expr<A>, Expr<F>, Expr<G>, Expr<H>, Expr<I>, Expr<J>, Expr<K>, Expr<L>, Expr<M>, Expr<N>, Expr<O>, Expr<P>)>
[src]
pub fn call(
&self,
a: Expr<A>,
f: Expr<F>,
g: Expr<G>,
h: Expr<H>,
i: Expr<I>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
[src]
&self,
a: Expr<A>,
f: Expr<F>,
g: Expr<G>,
h: Expr<H>,
i: Expr<I>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
impl<R, A, E, F, G, H, I, J, K, L, M, N, O, P> FunHandle<Expr<R>, (Expr<A>, Expr<E>, Expr<F>, Expr<G>, Expr<H>, Expr<I>, Expr<J>, Expr<K>, Expr<L>, Expr<M>, Expr<N>, Expr<O>, Expr<P>)>
[src]
pub fn call(
&self,
a: Expr<A>,
e: Expr<E>,
f: Expr<F>,
g: Expr<G>,
h: Expr<H>,
i: Expr<I>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
[src]
&self,
a: Expr<A>,
e: Expr<E>,
f: Expr<F>,
g: Expr<G>,
h: Expr<H>,
i: Expr<I>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
impl<R, A, D, E, F, G, H, I, J, K, L, M, N, O, P> FunHandle<Expr<R>, (Expr<A>, Expr<D>, Expr<E>, Expr<F>, Expr<G>, Expr<H>, Expr<I>, Expr<J>, Expr<K>, Expr<L>, Expr<M>, Expr<N>, Expr<O>, Expr<P>)>
[src]
pub fn call(
&self,
a: Expr<A>,
d: Expr<D>,
e: Expr<E>,
f: Expr<F>,
g: Expr<G>,
h: Expr<H>,
i: Expr<I>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
[src]
&self,
a: Expr<A>,
d: Expr<D>,
e: Expr<E>,
f: Expr<F>,
g: Expr<G>,
h: Expr<H>,
i: Expr<I>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
impl<R, A, C, D, E, F, G, H, I, J, K, L, M, N, O, P> FunHandle<Expr<R>, (Expr<A>, Expr<C>, Expr<D>, Expr<E>, Expr<F>, Expr<G>, Expr<H>, Expr<I>, Expr<J>, Expr<K>, Expr<L>, Expr<M>, Expr<N>, Expr<O>, Expr<P>)>
[src]
pub fn call(
&self,
a: Expr<A>,
c: Expr<C>,
d: Expr<D>,
e: Expr<E>,
f: Expr<F>,
g: Expr<G>,
h: Expr<H>,
i: Expr<I>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
[src]
&self,
a: Expr<A>,
c: Expr<C>,
d: Expr<D>,
e: Expr<E>,
f: Expr<F>,
g: Expr<G>,
h: Expr<H>,
i: Expr<I>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
impl<R, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> FunHandle<Expr<R>, (Expr<A>, Expr<B>, Expr<C>, Expr<D>, Expr<E>, Expr<F>, Expr<G>, Expr<H>, Expr<I>, Expr<J>, Expr<K>, Expr<L>, Expr<M>, Expr<N>, Expr<O>, Expr<P>)>
[src]
pub fn call(
&self,
a: Expr<A>,
b: Expr<B>,
c: Expr<C>,
d: Expr<D>,
e: Expr<E>,
f: Expr<F>,
g: Expr<G>,
h: Expr<H>,
i: Expr<I>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
[src]
&self,
a: Expr<A>,
b: Expr<B>,
c: Expr<C>,
d: Expr<D>,
e: Expr<E>,
f: Expr<F>,
g: Expr<G>,
h: Expr<H>,
i: Expr<I>,
j: Expr<J>,
k: Expr<K>,
l: Expr<L>,
m: Expr<M>,
n: Expr<N>,
o: Expr<O>,
p: Expr<P>
) -> Expr<R>
Create an expression representing a function call to this function.
See the documentation of FunHandle
for examples.
Trait Implementations
impl<R: Clone, A: Clone> Clone for FunHandle<R, A>
[src]
impl<R: Debug, A: Debug> Debug for FunHandle<R, A>
[src]
impl<R: PartialEq, A: PartialEq> PartialEq<FunHandle<R, A>> for FunHandle<R, A>
[src]
fn eq(&self, other: &FunHandle<R, A>) -> bool
[src]
fn ne(&self, other: &FunHandle<R, A>) -> bool
[src]
impl<R, A> StructuralPartialEq for FunHandle<R, A>
[src]
Auto Trait Implementations
impl<R, A> RefUnwindSafe for FunHandle<R, A> where
A: RefUnwindSafe,
R: RefUnwindSafe,
[src]
A: RefUnwindSafe,
R: RefUnwindSafe,
impl<R, A> Send for FunHandle<R, A> where
A: Send,
R: Send,
[src]
A: Send,
R: Send,
impl<R, A> Sync for FunHandle<R, A> where
A: Sync,
R: Sync,
[src]
A: Sync,
R: Sync,
impl<R, A> Unpin for FunHandle<R, A> where
A: Unpin,
R: Unpin,
[src]
A: Unpin,
R: Unpin,
impl<R, A> UnwindSafe for FunHandle<R, A> where
A: UnwindSafe,
R: UnwindSafe,
[src]
A: UnwindSafe,
R: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,