Skip to content

Commit

Permalink
Add impl Resource to remove warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
takasehideki committed Nov 4, 2024
1 parent 9b22da8 commit 1b87285
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions native/zenohex_nif/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::{Arc, RwLock};

use flume::Receiver;
use rustler::{Env, ResourceArc, Term};
use rustler::{Env, Resource, ResourceArc, Term};
use zenoh::{
prelude::sync::*, publication::Publisher, query::Reply, queryable::Query, queryable::Queryable,
sample::Sample, subscriber::PullSubscriber, subscriber::Subscriber, Session,
Expand Down Expand Up @@ -33,6 +33,15 @@ struct ReplyReceiverRef(Receiver<Reply>);
struct QueryRef(RwLock<Option<Query>>);
struct SampleRef(Sample);

impl Resource for SessionRef {}
impl Resource for PublisherRef {}
impl Resource for SubscriberRef {}
impl Resource for PullSubscriberRef {}
impl Resource for QueryableRef {}
impl Resource for ReplyReceiverRef {}
impl Resource for QueryRef {}
impl Resource for SampleRef {}

#[rustler::nif(schedule = "DirtyIo")]
fn zenoh_open(config: crate::config::ExConfig) -> Result<ResourceArc<SessionRef>, String> {
let config: zenoh::prelude::config::Config = config.into();
Expand All @@ -43,14 +52,14 @@ fn zenoh_open(config: crate::config::ExConfig) -> Result<ResourceArc<SessionRef>
}

fn load(env: Env, _term: Term) -> bool {
rustler::resource!(SessionRef, env);
rustler::resource!(PublisherRef, env);
rustler::resource!(SubscriberRef, env);
rustler::resource!(PullSubscriberRef, env);
rustler::resource!(QueryableRef, env);
rustler::resource!(ReplyReceiverRef, env);
rustler::resource!(QueryRef, env);
rustler::resource!(SampleRef, env);
env.register::<SessionRef>().unwrap();
env.register::<PublisherRef>().unwrap();
env.register::<SubscriberRef>().unwrap();
env.register::<PullSubscriberRef>().unwrap();
env.register::<QueryableRef>().unwrap();
env.register::<ReplyReceiverRef>().unwrap();
env.register::<QueryRef>().unwrap();
env.register::<SampleRef>().unwrap();
true
}

Expand Down

0 comments on commit 1b87285

Please sign in to comment.