Benjamin-Philip
Generic Structs with Rustler
The Problem
I have the following structs:
pub struct ExAfRef<T: HasAfEnum>(pub RwLock<Array<T>>);
#[derive(NifStruct)]
#[module = "ExAF.Backend"]
pub struct ExAf<T>
where
T: HasAfEnum,
{
pub resource: ResourceArc<ExAfRef<T>>,
}
On compiling it passes the following the error:
error[E0107]: missing generics for struct `datatypes::ExAf`
--> src/datatypes.rs:10:12
|
10 | pub struct ExAf<T>
| ^^^^ expected 1 generic argument
|
note: struct defined here, with 1 generic parameter: `T`
--> src/datatypes.rs:10:12
|
10 | pub struct ExAf<T>
| ^^^^ -
help: add missing generic argument
|
10 | pub struct ExAf<T><T>
| ~~~~~~~
However when I comment out / remove the rustler specific bits, I don’t have the error:
pub struct ExAfRef<T: HasAfEnum>(pub RwLock<Array<T>>);
pub struct ExAf<T>
where
T: HasAfEnum,
{
pub resource: ExAfRef<T>,
}
How can I use generic structs with rustler?
What I am trying to do
I am writing some bindings to arrayfire using their rust crate. Their Array struct is typed and support multiple types like i64 and f64. I am trying to access references (and create references) to Arrays from Elixir. I figured that writing a struct with a trait bound to support all the various types would be the best way to do it.
If there is a better way of doing this without a generic struct, I would be happy to implement it.
Marked As Solved
SeokminHong
Popular in Questions
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
Hello everyone,
I try to use an Javascript Event Handler in my root.html.leex file.
Therefore I created a function in the app.js file: ...
New
Other popular topics
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









