-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New rustler::init! errors #310
Comments
@evnu Thanks for that. Please we need better examples and directions for moving to the new syntax. for example:
my attempt:
|
Not in
#[rustler::nif(schedule = "DirtyIo", name = "recv")]
fn receive(tdlib: ResourceArc<XTdlib>, timeout: f64) -> Term {
tdlib.tdlib.receive(timeout)
} I assume this fails with a type error? NIFs with the new syntax can either return a type which can be converted automatically, or you can still return plain-old pub fn unowned_to_owned<'a>(env: Env<'a>, binary: Binary<'a>) -> NifResult<Binary<'a>> {
let mut copied = binary.to_owned().unwrap();
copied.as_mut_slice()[0] = 1;
Ok(copied.release(env))
} In the case of your #[rustler::nif(schedule = "DirtyIo", name = "recv")]
fn receive(tdlib: ResourceArc<XTdlib>, timeout: f64) -> Option<Response> {
tdlib.tdlib.receive(timeout)
} With regard to converting to the new syntax, I would propose to do that piece-by-piece: prefix your NIFs with |
@evnu Thanks for your assistance, but now it just throws a bunch of errors ...
compile - errors
|
Your function is called
Your function is called
This is caused by the function arguments: #[rustler::nif(schedule = "DirtyIo", name = "recv")]
fn receive<'a>(env: Env<'a>, args: &[Term<'a>]) -> Result<Term<'a>, Error> {
let tdlib: ResourceArc<XTdlib> = args[0].decode()?;
let timeout: f64 = args[1].decode()?;
match tdlib.tdlib.receive(timeout) {
None => Ok(atoms::null().encode(env)),
Some(resp) => Ok((atoms::ok(), resp).encode(env)),
}
} Rustler is not able to decode #[rustler::nif(schedule = "DirtyIo", name = "recv")]
fn receive<'a>(env: Env<'a>, tdlib: ResourceArc<XTdlib>, timeout: f64) -> Result<Term<'a>, Error> {
match tdlib.tdlib.receive(timeout) {
None => Ok(atoms::null().encode(env)),
Some(resp) => Ok((atoms::ok(), resp).encode(env)),
}
} (@scrogson is there a backwards compatible way to make the old function syntax work? I don't know if the changelog is explicit enough wrt to this) |
@evnu no, there is not. The new macros do not work with the slice of terms. |
Please how do we conditionally return
|
Call
|
@filmor Thanks. Please i'm still not clear on this. These were the old format:
This is what i'm trying now, with the added
Please kindly help me clarify. |
In your execute function you need to pass in |
oh, ok. thanks @scrogson |
Please i get this error trying to translate the following to new rustler syntax:
previous:
I'm not sure how to proceed.
The text was updated successfully, but these errors were encountered: