Skip to content

Commit

Permalink
Use SerdeTerm for the 'readme' example
Browse files Browse the repository at this point in the history
  • Loading branch information
filmor committed Jan 9, 2024
1 parent a7f4398 commit 8a25089
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions rustler_tests/native/rustler_serde_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ mod test;
mod types;

use crate::types::Animal;
use rustler::serde::{atoms, from_term, to_term, Deserializer, Error, Serializer};
use rustler::SerdeTerm;
use rustler::{types::tuple, Encoder, Env, NifResult, Term};
use rustler::serde::{atoms, Deserializer, Error, Serializer};
use rustler::{types::tuple, Encoder, Env, NifResult, SerdeTerm, Term};

init! {
"Elixir.SerdeRustlerTests",
Expand All @@ -35,9 +34,9 @@ init! {

/// Implements the README example.
#[nif]
pub fn readme<'a>(env: Env<'a>, SerdeTerm(animal): SerdeTerm<Animal>) -> NifResult<Term<'a>> {
pub fn readme(SerdeTerm(animal): SerdeTerm<Animal>) -> SerdeTerm<Animal> {
// println!("\n deserialized animal from README example: {:?}", animal);
to_term(env, animal).map_err(|err| err.into())
SerdeTerm(animal)
}

/// Deserializes anything from an Elixir term and subsequently serializes the result back into an Elixir term, returning it.
Expand Down

0 comments on commit 8a25089

Please sign in to comment.