diff --git a/rustler/build.rs b/rustler/build.rs index ce9c92f8..97faecbe 100644 --- a/rustler/build.rs +++ b/rustler/build.rs @@ -49,7 +49,7 @@ fn write_variadic_fn_type(out: &mut String, args: &str, ret: &str) { } pub struct CallbacksApiBuilder<'a>(&'a mut String); -impl<'a> ApiBuilder for CallbacksApiBuilder<'a> { +impl ApiBuilder for CallbacksApiBuilder<'_> { fn init(&mut self) { writeln!(self.0, "#[allow(dead_code)]").unwrap(); writeln!(self.0, "#[derive(Default, Copy, Clone)]").unwrap(); @@ -78,7 +78,7 @@ impl<'a> ApiBuilder for CallbacksApiBuilder<'a> { } pub struct ForwardersApiBuilder<'a>(&'a mut String); -impl<'a> ApiBuilder for ForwardersApiBuilder<'a> { +impl ApiBuilder for ForwardersApiBuilder<'_> { fn func(&mut self, ret: &str, name: &str, args: &str) { // This regex takes a list of args with types and return only the name of the args. // @@ -135,7 +135,7 @@ impl<'a> ApiBuilder for ForwardersApiBuilder<'a> { pub struct WriterBuilder<'a>(&'a mut String); -impl<'a> ApiBuilder for WriterBuilder<'a> { +impl ApiBuilder for WriterBuilder<'_> { fn init(&mut self) { write!( self.0, diff --git a/rustler/src/dynamic.rs b/rustler/src/dynamic.rs index 5b6dafa2..0f16031a 100644 --- a/rustler/src/dynamic.rs +++ b/rustler/src/dynamic.rs @@ -85,7 +85,7 @@ macro_rules! impl_check { } /// ## Type checks -impl<'a> Term<'a> { +impl Term<'_> { /// Returns an enum representing which type the term is. /// Note that using the individual `is_*` functions is more /// efficient for checking a single type. diff --git a/rustler/src/env.rs b/rustler/src/env.rs index 7b7efb84..db78a345 100644 --- a/rustler/src/env.rs +++ b/rustler/src/env.rs @@ -35,7 +35,7 @@ pub struct Env<'a> { /// Two environments are equal if they're the same `NIF_ENV` value. /// /// A `Env<'a>` is equal to a `Env<'b>` if and only if `'a` and `'b` are the same lifetime. -impl<'a, 'b> PartialEq> for Env<'a> { +impl<'b> PartialEq> for Env<'_> { fn eq(&self, other: &Env<'b>) -> bool { self.env == other.env } diff --git a/rustler/src/resource/registration.rs b/rustler/src/resource/registration.rs index 85e7a649..87c000b4 100644 --- a/rustler/src/resource/registration.rs +++ b/rustler/src/resource/registration.rs @@ -24,7 +24,7 @@ unsafe impl Sync for Registration {} inventory::collect!(Registration); -impl<'a> Env<'a> { +impl Env<'_> { /// Register a resource type, see `Registration::register`. pub fn register(&self) -> Result<(), ResourceInitError> { Registration::new::().register(*self) diff --git a/rustler/src/resource/traits.rs b/rustler/src/resource/traits.rs index ddb8552b..24fe09ec 100644 --- a/rustler/src/resource/traits.rs +++ b/rustler/src/resource/traits.rs @@ -12,6 +12,7 @@ type NifResourcePtr = *const ErlNifResourceType; static mut RESOURCE_TYPES: OnceLock> = OnceLock::new(); /// Register an Erlang resource type handle for a particular type given by its `TypeId` +#[allow(static_mut_refs)] pub(crate) unsafe fn register_resource_type(type_id: TypeId, resource_type: NifResourcePtr) { RESOURCE_TYPES.get_or_init(Default::default); RESOURCE_TYPES @@ -64,6 +65,7 @@ pub trait Resource: Sized + Send + Sync + 'static { #[doc(hidden)] pub(crate) trait ResourceExt: 'static { /// Get the NIF resource type handle for this type if it had been registered before + #[allow(static_mut_refs)] fn get_resource_type() -> Option { let map = unsafe { RESOURCE_TYPES.get()? }; map.get(&TypeId::of::()) diff --git a/rustler/src/return.rs b/rustler/src/return.rs index 6218de81..6c3ea625 100644 --- a/rustler/src/return.rs +++ b/rustler/src/return.rs @@ -7,7 +7,7 @@ pub enum Return<'a> { Error(Error), } -unsafe impl<'b> NifReturnable for Return<'b> { +unsafe impl NifReturnable for Return<'_> { unsafe fn into_returned(self, env: Env) -> NifReturned { match self { Return::Term(inner) => NifReturned::Term(inner.as_c_arg()), diff --git a/rustler/src/sys/functions.rs b/rustler/src/sys/functions.rs index a81cdbe1..5b7eaca3 100644 --- a/rustler/src/sys/functions.rs +++ b/rustler/src/sys/functions.rs @@ -10,6 +10,7 @@ pub unsafe fn internal_set_symbols(callbacks: DynNifCallbacks) { DYN_NIF_CALLBACKS = callbacks; } +#[allow(static_mut_refs)] pub unsafe fn internal_write_symbols() { let filler = nif_filler::new(); DYN_NIF_CALLBACKS.write_symbols(filler); diff --git a/rustler/src/term.rs b/rustler/src/term.rs index 99ceaa2b..9d40abe8 100644 --- a/rustler/src/term.rs +++ b/rustler/src/term.rs @@ -17,7 +17,7 @@ pub struct Term<'a> { env: Env<'a>, } -impl<'a> Debug for Term<'a> { +impl Debug for Term<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { crate::wrapper::term::fmt(self.as_c_arg(), f) } @@ -121,12 +121,12 @@ impl<'a> Term<'a> { } } -impl<'a> PartialEq for Term<'a> { +impl PartialEq for Term<'_> { fn eq(&self, other: &Term) -> bool { unsafe { enif_is_identical(self.as_c_arg(), other.as_c_arg()) == 1 } } } -impl<'a> Eq for Term<'a> {} +impl Eq for Term<'_> {} fn cmp(lhs: &Term, rhs: &Term) -> Ordering { let ord = unsafe { enif_compare(lhs.as_c_arg(), rhs.as_c_arg()) }; @@ -137,7 +137,7 @@ fn cmp(lhs: &Term, rhs: &Term) -> Ordering { } } -impl<'a> Ord for Term<'a> { +impl Ord for Term<'_> { fn cmp(&self, other: &Term) -> Ordering { cmp(self, other) } @@ -148,7 +148,7 @@ impl<'a> PartialOrd for Term<'a> { } } -impl<'a> Hash for Term<'a> { +impl Hash for Term<'_> { fn hash(&self, state: &mut H) { // As far as I can see, there is really no way // to get a seed from the hasher. This is definitely @@ -157,5 +157,5 @@ impl<'a> Hash for Term<'a> { } } -unsafe impl<'a> Sync for Term<'a> {} -unsafe impl<'a> Send for Term<'a> {} +unsafe impl Sync for Term<'_> {} +unsafe impl Send for Term<'_> {} diff --git a/rustler/src/types/atom.rs b/rustler/src/types/atom.rs index 02d85f34..594e4ea1 100644 --- a/rustler/src/types/atom.rs +++ b/rustler/src/types/atom.rs @@ -106,7 +106,7 @@ impl<'a> PartialEq> for Atom { } /// ## Atom terms -impl<'a> Term<'a> { +impl Term<'_> { /// When the term is an atom, this method will return the string /// representation of it. /// diff --git a/rustler/src/types/big_int.rs b/rustler/src/types/big_int.rs index 53aa9f33..7c0dfd15 100644 --- a/rustler/src/types/big_int.rs +++ b/rustler/src/types/big_int.rs @@ -1,18 +1,3 @@ -use crate::{Decoder, Encoder, Env, Error, NifResult, Term}; - -use num_bigint::{BigInt, Sign}; - -// From https://www.erlang.org/doc/apps/erts/erl_ext_dist.html -const EXTERNAL_TERM_FORMAT_VERSION: u8 = 131; -const SMALL_INTEGER: u8 = 97; -const INTEGER: u8 = 98; -const SMALL_BIG_EXT: u8 = 110; -const LARGE_BIG_EXT: u8 = 111; - -crate::atoms! { - big_int_encoder_invalid_bytes -} - /// Implementation of [Decoder](rustler::Decoder) and [Encoder](rustler::Encoder) traits for /// num-bigint. /// @@ -48,6 +33,20 @@ crate::atoms! { /// } /// ``` /// +use crate::{Decoder, Encoder, Env, Error, NifResult, Term}; + +use num_bigint::{BigInt, Sign}; + +// From https://www.erlang.org/doc/apps/erts/erl_ext_dist.html +const EXTERNAL_TERM_FORMAT_VERSION: u8 = 131; +const SMALL_INTEGER: u8 = 97; +const INTEGER: u8 = 98; +const SMALL_BIG_EXT: u8 = 110; +const LARGE_BIG_EXT: u8 = 111; + +crate::atoms! { + big_int_encoder_invalid_bytes +} fn decode_big_integer(input: &[u8]) -> NifResult { if Some(&EXTERNAL_TERM_FORMAT_VERSION) != input.first() { diff --git a/rustler/src/types/binary.rs b/rustler/src/types/binary.rs index 8cfa9328..784854ba 100644 --- a/rustler/src/types/binary.rs +++ b/rustler/src/types/binary.rs @@ -393,12 +393,12 @@ impl<'a> Binary<'a> { } } -impl<'a> Borrow<[u8]> for Binary<'a> { +impl Borrow<[u8]> for Binary<'_> { fn borrow(&self) -> &[u8] { self.as_slice() } } -impl<'a> Deref for Binary<'a> { +impl Deref for Binary<'_> { type Target = [u8]; fn deref(&self) -> &[u8] { self.as_slice() @@ -410,7 +410,7 @@ impl<'a> Decoder<'a> for Binary<'a> { Binary::from_term(term) } } -impl<'a> Encoder for Binary<'a> { +impl Encoder for Binary<'_> { fn encode<'b>(&self, env: Env<'b>) -> Term<'b> { self.to_term(env) } @@ -479,13 +479,13 @@ impl<'a> From> for Term<'a> { } } -impl<'a> Deref for NewBinary<'a> { +impl Deref for NewBinary<'_> { type Target = [u8]; fn deref(&self) -> &[u8] { self.as_slice() } } -impl<'a> DerefMut for NewBinary<'a> { +impl DerefMut for NewBinary<'_> { fn deref_mut(&mut self) -> &mut [u8] { self.as_mut_slice() } diff --git a/rustler/src/types/list.rs b/rustler/src/types/list.rs index b9b3d21f..22048d4a 100644 --- a/rustler/src/types/list.rs +++ b/rustler/src/types/list.rs @@ -122,7 +122,7 @@ where } } -impl<'a, T> Encoder for &'a [T] +impl Encoder for &[T] where T: Encoder, { diff --git a/rustler/src/types/local_pid.rs b/rustler/src/types/local_pid.rs index d46726ad..d49f6417 100644 --- a/rustler/src/types/local_pid.rs +++ b/rustler/src/types/local_pid.rs @@ -59,7 +59,7 @@ impl Ord for LocalPid { } } -impl<'a> Env<'a> { +impl Env<'_> { /// Return the calling process's pid. /// /// # Panics diff --git a/rustler/src/types/map.rs b/rustler/src/types/map.rs index 72b1b55b..0e6e59de 100644 --- a/rustler/src/types/map.rs +++ b/rustler/src/types/map.rs @@ -259,7 +259,7 @@ impl<'a> SimpleMapIterator<'a> { } } -impl<'a> Drop for SimpleMapIterator<'a> { +impl Drop for SimpleMapIterator<'_> { fn drop(&mut self) { if let Some(iter) = self.iter.as_mut() { unsafe { @@ -314,7 +314,7 @@ impl<'a> Iterator for MapIterator<'a> { } } -impl<'a> DoubleEndedIterator for MapIterator<'a> { +impl DoubleEndedIterator for MapIterator<'_> { fn next_back(&mut self) -> Option { self.reverse.next().and_then(|(key, value)| { if self.forward.last_key == Some(key) { diff --git a/rustler/src/types/mod.rs b/rustler/src/types/mod.rs index c3f11ced..c7b72005 100644 --- a/rustler/src/types/mod.rs +++ b/rustler/src/types/mod.rs @@ -51,7 +51,7 @@ pub trait Decoder<'a>: Sized + 'a { fn decode(term: Term<'a>) -> NifResult; } -impl<'a> Encoder for Term<'a> { +impl Encoder for Term<'_> { fn encode<'b>(&self, env: Env<'b>) -> Term<'b> { self.in_env(env) } @@ -62,7 +62,7 @@ impl<'a> Decoder<'a> for Term<'a> { } } -impl<'a, T> Encoder for &'a T +impl Encoder for &T where T: Encoder, { diff --git a/rustler/src/types/primitive.rs b/rustler/src/types/primitive.rs index 2ec0b7c8..efceb325 100644 --- a/rustler/src/types/primitive.rs +++ b/rustler/src/types/primitive.rs @@ -68,7 +68,7 @@ impl_number_transcoder!(isize, i64, enif_make_int64, enif_get_int64); impl_number_encoder!(f32, f64, enif_make_double); // Manual Decoder impls for floats so they can fall back to decoding from integer terms -impl<'a> Decoder<'a> for f64 { +impl Decoder<'_> for f64 { fn decode(term: Term) -> NifResult { #![allow(unused_unsafe)] let mut res: f64 = Default::default(); @@ -80,7 +80,7 @@ impl<'a> Decoder<'a> for f64 { } } -impl<'a> Decoder<'a> for f32 { +impl Decoder<'_> for f32 { fn decode(term: Term) -> NifResult { let res: f64 = term.decode()?; let res = res as f32; diff --git a/rustler/src/types/reference.rs b/rustler/src/types/reference.rs index 013e3263..9514f854 100644 --- a/rustler/src/types/reference.rs +++ b/rustler/src/types/reference.rs @@ -8,7 +8,7 @@ use crate::sys::enif_make_ref; #[derive(PartialEq, Eq, Clone, Copy)] pub struct Reference<'a>(Term<'a>); -impl<'a> Reference<'a> { +impl Reference<'_> { /// Returns a representation of self in the given Env. /// /// If the term is already is in the provided env, it will be directly returned. Otherwise @@ -50,7 +50,7 @@ impl<'a> Decoder<'a> for Reference<'a> { } } -impl<'a> Encoder for Reference<'a> { +impl Encoder for Reference<'_> { fn encode<'b>(&self, env: Env<'b>) -> Term<'b> { self.0.encode(env) } diff --git a/rustler/src/types/string.rs b/rustler/src/types/string.rs index 4833bd2c..9b3cc335 100644 --- a/rustler/src/types/string.rs +++ b/rustler/src/types/string.rs @@ -19,7 +19,7 @@ impl<'a> Decoder<'a> for &'a str { use std::io::Write; -impl<'a> Encoder for &'a str { +impl Encoder for &str { fn encode<'b>(&self, env: Env<'b>) -> Term<'b> { (*self).encode(env) } diff --git a/rustler/src/types/tuple.rs b/rustler/src/types/tuple.rs index 2d4daaee..5048e710 100644 --- a/rustler/src/types/tuple.rs +++ b/rustler/src/types/tuple.rs @@ -1,15 +1,6 @@ use crate::wrapper::{tuple, NIF_TERM}; use crate::{Decoder, Encoder, Env, Error, NifResult, Term}; -/// ## Tuple terms -//impl<'a> Term<'a> { -// -// pub fn tuple_to_vec(self) -> NifResult> { -// -// } -// -//} - /// Convert an Erlang tuple to a Rust vector. (To convert to a Rust tuple, use `term.decode()` /// instead.) /// diff --git a/rustler_codegen/src/lib.rs b/rustler_codegen/src/lib.rs index 8399f49f..9792a3f6 100644 --- a/rustler_codegen/src/lib.rs +++ b/rustler_codegen/src/lib.rs @@ -129,7 +129,6 @@ pub fn nif(args: TokenStream, input: TokenStream) -> TokenStream { /// /// Then the traits `Encoder` and `Decoder` are derived automatically for your Rust struct /// such that you can use the Elixir struct definition for it. - #[proc_macro_derive(NifStruct, attributes(module, rustler))] pub fn nif_struct(input: TokenStream) -> TokenStream { let ast = syn::parse(input).unwrap();