@@ -248,6 +248,7 @@ pub struct Binary<'a> {
248
248
249
249
impl < ' a > Binary < ' a > {
250
250
/// Consumes `owned` and returns an immutable `Binary`.
251
+ #[ inline]
251
252
pub fn from_owned ( owned : OwnedBinary , env : Env < ' a > ) -> Self {
252
253
// We are transferring ownership of `owned`'s data to the
253
254
// environment. Therefore, we need to prevent `owned`'s destructor being
@@ -269,6 +270,7 @@ impl<'a> Binary<'a> {
269
270
///
270
271
/// If allocation fails, an error will be returned.
271
272
#[ allow( clippy:: wrong_self_convention) ]
273
+ #[ inline]
272
274
pub fn to_owned ( & self ) -> Option < OwnedBinary > {
273
275
OwnedBinary :: from_unowned ( self )
274
276
}
@@ -278,6 +280,7 @@ impl<'a> Binary<'a> {
278
280
/// # Errors
279
281
///
280
282
/// If `term` is not a binary, an error will be returned.
283
+ #[ inline]
281
284
pub fn from_term ( term : Term < ' a > ) -> Result < Self , Error > {
282
285
let mut binary = MaybeUninit :: uninit ( ) ;
283
286
if unsafe {
@@ -315,6 +318,7 @@ impl<'a> Binary<'a> {
315
318
/// # Errors
316
319
///
317
320
/// If `term` is not an `iolist`, an error will be returned.
321
+ #[ inline]
318
322
pub fn from_iolist ( term : Term < ' a > ) -> Result < Self , Error > {
319
323
let mut binary = MaybeUninit :: uninit ( ) ;
320
324
if unsafe {
@@ -338,11 +342,13 @@ impl<'a> Binary<'a> {
338
342
339
343
/// Returns an Erlang term representation of `self`.
340
344
#[ allow( clippy:: wrong_self_convention) ]
345
+ #[ inline]
341
346
pub fn to_term < ' b > ( & self , env : Env < ' b > ) -> Term < ' b > {
342
347
self . term . in_env ( env)
343
348
}
344
349
345
350
/// Extracts a slice containing the entire binary.
351
+ #[ inline]
346
352
pub fn as_slice ( & self ) -> & ' a [ u8 ] {
347
353
unsafe { :: std:: slice:: from_raw_parts ( self . buf , self . size ) }
348
354
}
@@ -355,6 +361,7 @@ impl<'a> Binary<'a> {
355
361
/// # Errors
356
362
///
357
363
/// If `offset + length` is out of bounds, an error will be returned.
364
+ #[ inline]
358
365
pub fn make_subbinary ( & self , offset : usize , length : usize ) -> NifResult < Binary < ' a > > {
359
366
let min_len = length. checked_add ( offset) ;
360
367
if min_len. ok_or ( Error :: BadArg ) ? > self . size {
@@ -452,40 +459,47 @@ pub struct NewBinary<'a> {
452
459
453
460
impl < ' a > NewBinary < ' a > {
454
461
/// Allocates a new `NewBinary`
462
+ #[ inline]
455
463
pub fn new ( env : Env < ' a > , size : usize ) -> Self {
456
464
let ( buf, term) = unsafe { new_binary ( env, size) } ;
457
465
NewBinary { buf, term, size }
458
466
}
459
467
/// Extracts a slice containing the entire binary.
468
+ #[ inline]
460
469
pub fn as_slice ( & self ) -> & [ u8 ] {
461
470
unsafe { :: std:: slice:: from_raw_parts ( self . buf , self . size ) }
462
471
}
463
472
464
473
/// Extracts a mutable slice of the entire binary.
474
+ #[ inline]
465
475
pub fn as_mut_slice ( & mut self ) -> & mut [ u8 ] {
466
476
unsafe { :: std:: slice:: from_raw_parts_mut ( self . buf , self . size ) }
467
477
}
468
478
}
469
479
470
480
impl < ' a > From < NewBinary < ' a > > for Binary < ' a > {
481
+ #[ inline]
471
482
fn from ( new_binary : NewBinary < ' a > ) -> Self {
472
483
Binary :: from_term ( new_binary. term ) . unwrap ( )
473
484
}
474
485
}
475
486
476
487
impl < ' a > From < NewBinary < ' a > > for Term < ' a > {
488
+ #[ inline]
477
489
fn from ( new_binary : NewBinary < ' a > ) -> Self {
478
490
new_binary. term
479
491
}
480
492
}
481
493
482
494
impl Deref for NewBinary < ' _ > {
483
495
type Target = [ u8 ] ;
496
+ #[ inline]
484
497
fn deref ( & self ) -> & [ u8 ] {
485
498
self . as_slice ( )
486
499
}
487
500
}
488
501
impl DerefMut for NewBinary < ' _ > {
502
+ #[ inline]
489
503
fn deref_mut ( & mut self ) -> & mut [ u8 ] {
490
504
self . as_mut_slice ( )
491
505
}
0 commit comments