File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -236,6 +236,32 @@ impl Drop for OwnedBinary {
236236unsafe impl Send for OwnedBinary { }
237237unsafe impl Sync for OwnedBinary { }
238238
239+ impl FromIterator < u8 > for OwnedBinary {
240+ fn from_iter < T : IntoIterator < Item = u8 > > ( iter : T ) -> Self {
241+ let mut iter = iter. into_iter ( ) ;
242+ let ( lower, upper) = iter. size_hint ( ) ;
243+ let mut bin = OwnedBinary :: new ( upper. unwrap_or ( lower) ) . expect ( "Allocation failed" ) ;
244+ let mut i = 0 ;
245+ loop {
246+ match iter. next ( ) {
247+ None => {
248+ if bin. len ( ) != i {
249+ bin. realloc_or_copy ( i) ;
250+ }
251+ return bin;
252+ }
253+ Some ( x) => {
254+ if bin. len ( ) <= i {
255+ bin. realloc_or_copy ( i + i / 2 + 1 ) ;
256+ }
257+ bin. as_mut_slice ( ) [ i] = x;
258+ i += 1 ;
259+ }
260+ }
261+ }
262+ }
263+ }
264+
239265/// An immutable smart-pointer to an Erlang binary.
240266///
241267/// See [module-level doc](index.html) for more information.
You can’t perform that action at this time.
0 commit comments