@@ -28,9 +28,9 @@ pub use typed_term::*;
2828//pub use map::*;
2929pub use boxed:: * ;
3030
31+ use core:: alloc:: { AllocErr , Layout } ;
3132use core:: fmt;
3233use core:: ptr;
33- use core:: alloc:: { Layout , AllocErr } ;
3434
3535use super :: ProcessControlBlock ;
3636
@@ -105,16 +105,16 @@ impl crate::borrow::CloneToProcess for MapHeader {
105105}
106106
107107/// Constructs a binary from the given string, and associated with the given process
108- ///
108+ ///
109109/// For inputs greater than 64 bytes in size, the resulting binary data is allocated
110110/// on the global shared heap, and reference counted (a `ProcBin`), the header to that
111111/// binary is allocated on the process heap, and the data is placed in the processes'
112112/// virtual binary heap, and a boxed term is returned which can then be placed on the stack,
113113/// or as part of a larger structure if desired.
114- ///
114+ ///
115115/// For inputs less than or equal to 64 bytes, both the header and data are allocated
116116/// on the process heap, and a boxed term is returned as described above.
117- ///
117+ ///
118118/// NOTE: If allocation fails for some reason, `Err(AllocErr)` is returned, this usually
119119/// indicates that a process needs to be garbage collected, but in some cases may indicate
120120/// that the global heap is out of space.
@@ -140,7 +140,8 @@ pub fn make_binary_from_str(process: &mut ProcessControlBlock, s: &str) -> Resul
140140 let header_ptr = process. alloc_layout ( HeapBin :: layout ( s) ) ?. as_ptr ( ) as * mut HeapBin ;
141141 // Pointer to start of binary data
142142 let bin_ptr = header_ptr. offset ( 1 ) as * mut u8 ;
143- // Construct the right header based on whether input string is only ASCII or includes UTF8
143+ // Construct the right header based on whether input string is only ASCII or includes
144+ // UTF8
144145 let header = if s. is_ascii ( ) {
145146 HeapBin :: new_latin1 ( len)
146147 } else {
@@ -158,21 +159,24 @@ pub fn make_binary_from_str(process: &mut ProcessControlBlock, s: &str) -> Resul
158159}
159160
160161/// Constructs a binary from the given byte slice, and associated with the given process
161- ///
162+ ///
162163/// For inputs greater than 64 bytes in size, the resulting binary data is allocated
163164/// on the global shared heap, and reference counted (a `ProcBin`), the header to that
164165/// binary is allocated on the process heap, and the data is placed in the processes'
165166/// virtual binary heap, and a boxed term is returned which can then be placed on the stack,
166167/// or as part of a larger structure if desired.
167- ///
168+ ///
168169/// For inputs less than or equal to 64 bytes, both the header and data are allocated
169170/// on the process heap, and a boxed term is returned as described above.
170- ///
171+ ///
171172/// NOTE: If allocation fails for some reason, `Err(AllocErr)` is returned, this usually
172173/// indicates that a process needs to be garbage collected, but in some cases may indicate
173174/// that the global heap is out of space.
174175#[ inline]
175- pub fn make_binary_from_bytes ( process : & mut ProcessControlBlock , s : & [ u8 ] ) -> Result < Term , AllocErr > {
176+ pub fn make_binary_from_bytes (
177+ process : & mut ProcessControlBlock ,
178+ s : & [ u8 ] ,
179+ ) -> Result < Term , AllocErr > {
176180 let len = s. len ( ) ;
177181 // Allocate ProcBins for sizes greater than 64 bytes
178182 if len > 64 {
@@ -190,10 +194,12 @@ pub fn make_binary_from_bytes(process: &mut ProcessControlBlock, s: &[u8]) -> Re
190194 } else {
191195 unsafe {
192196 // Allocates space on the process heap for the header + data
193- let header_ptr = process. alloc_layout ( HeapBin :: layout_bytes ( s) ) ?. as_ptr ( ) as * mut HeapBin ;
197+ let header_ptr =
198+ process. alloc_layout ( HeapBin :: layout_bytes ( s) ) ?. as_ptr ( ) as * mut HeapBin ;
194199 // Pointer to start of binary data
195200 let bin_ptr = header_ptr. offset ( 1 ) as * mut u8 ;
196- // Construct the right header based on whether input string is only ASCII or includes UTF8
201+ // Construct the right header based on whether input string is only ASCII or includes
202+ // UTF8
197203 let header = HeapBin :: new ( len) ;
198204 // Write header
199205 ptr:: write ( header_ptr, header) ;
@@ -203,19 +209,22 @@ pub fn make_binary_from_bytes(process: &mut ProcessControlBlock, s: &[u8]) -> Re
203209 let result = Term :: from_raw ( header_ptr as usize | Term :: FLAG_BOXED ) ;
204210 Ok ( result)
205211 }
206- }
212+ }
207213}
208214
209215/// Constructs a `Tuple` from a slice of `Term`
210- ///
216+ ///
211217/// Be aware that this does not allocate non-immediate terms in `elements` on the process heap,
212218/// it is expected that the slice provided is constructed from either immediate terms, or
213219/// terms which were returned from other constructor functions, e.g. `make_binary_from_str`.
214- ///
220+ ///
215221/// The resulting `Term` is a box pointing to the tuple header, and can itself be used in
216222/// a slice passed to `make_tuple_from_slice` to produce nested tuples.
217223#[ inline]
218- pub fn make_tuple_from_slice ( process : & mut ProcessControlBlock , elements : & [ Term ] ) -> Result < Term , AllocErr > {
224+ pub fn make_tuple_from_slice (
225+ process : & mut ProcessControlBlock ,
226+ elements : & [ Term ] ,
227+ ) -> Result < Term , AllocErr > {
219228 let len = elements. len ( ) ;
220229 let layout = Tuple :: layout ( len) ;
221230 let tuple_ptr = unsafe { process. alloc_layout ( layout) ?. as_ptr ( ) as * mut Tuple } ;
@@ -311,4 +320,4 @@ pub(crate) fn to_word_size(bytes: usize) -> usize {
311320pub ( crate ) fn word_size_of < T : Sized > ( ) -> usize {
312321 use core:: mem;
313322 to_word_size ( mem:: size_of :: < T > ( ) )
314- }
323+ }
0 commit comments