Skip to content

Commit

Permalink
Simple usage example in the README. (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgeoga authored Aug 18, 2022
1 parent 86f06b6 commit 1a5aa9d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,24 @@ Proof of principle implementation of [JuliaLang/julia#13984](https://github.com/
This does not require LLVM trampoline support, which is not currently supported by LLVM
on all the architectures julia runs on ([JuliaLang/julia#27174](https://github.com/JuliaLang/julia/issues/27174)).
Other than this issue `@cfunction` should cover all of the use cases.

## Simple Usage Example

```julia
using FunctionWrappers
import FunctionWrappers: FunctionWrapper

# For a function that sends (x1::T1, x2::T2, ...) -> ::TN, you use
# a FunctionWrapper{TN, Tuple{T1, T2, ...}}.
struct TypeStableStruct
fun::FunctionWrapper{Float64, Tuple{Float64, Float64}}
second_arg::Float64
end

evaluate_strfun(str, arg) = str.fun(arg, str.second_arg)

example = TypeStableStruct(hypot, 1.0)

@code_warntype evaluate_strfun(example, 1.5) # all good
```

0 comments on commit 1a5aa9d

Please sign in to comment.