@@ -5,7 +5,9 @@ use super::{
55#[ cfg( all( not( feature = "std" ) , feature = "alloc" ) ) ]
66extern crate alloc;
77#[ cfg( all( not( feature = "std" ) , feature = "alloc" ) ) ]
8- use alloc:: { string:: String , vec, vec:: Vec } ;
8+ use alloc:: { boxed:: Box , string:: String , vec, vec:: Vec } ;
9+ #[ cfg( all( feature = "std" , feature = "alloc" ) ) ]
10+ use std:: boxed:: Box ;
911
1012// TODO: Use the Error type for conversions in this file.
1113
@@ -404,54 +406,55 @@ impl TryFrom<&ScVal> for Vec<u8> {
404406 }
405407}
406408
409+ #[ cfg( feature = "alloc" ) ]
407410impl From < ScVec > for ScVal {
408411 fn from ( v : ScVec ) -> Self {
409- ScVal :: Vec ( Some ( v ) )
412+ ScVal :: Vec ( Some ( Box :: new ( v ) ) )
410413 }
411414}
412415
413416#[ cfg( feature = "alloc" ) ]
414417impl < T : TryInto < ScVal > > TryFrom < Vec < T > > for ScVal {
415418 type Error = ( ) ;
416419 fn try_from ( v : Vec < T > ) -> Result < Self , ( ) > {
417- Ok ( ScVal :: Vec ( Some (
420+ Ok ( ScVal :: Vec ( Some ( Box :: new (
418421 v. into_iter ( )
419422 . map ( |t| <_ as TryInto < ScVal > >:: try_into ( t) )
420423 . collect :: < Result < Vec < _ > , _ > > ( ) // TODO: Impl conversion from Iterator to VecM in generated code.
421424 . map_err ( |_| ( ) ) ?
422425 . try_into ( )
423426 . map_err ( |_| ( ) ) ?,
424- ) ) )
427+ ) ) ) )
425428 }
426429}
427430
428431#[ cfg( feature = "alloc" ) ]
429432impl < T : TryInto < ScVal > + Clone > TryFrom < & Vec < T > > for ScVal {
430433 type Error = ( ) ;
431434 fn try_from ( v : & Vec < T > ) -> Result < Self , ( ) > {
432- Ok ( ScVal :: Vec ( Some (
435+ Ok ( ScVal :: Vec ( Some ( Box :: new (
433436 v. iter ( )
434437 . map ( |t| <_ as TryInto < ScVal > >:: try_into ( t. clone ( ) ) )
435438 . collect :: < Result < Vec < _ > , _ > > ( ) // TODO: Impl conversion from Iterator to VecM in generated code.
436439 . map_err ( |_| ( ) ) ?
437440 . try_into ( )
438441 . map_err ( |_| ( ) ) ?,
439- ) ) )
442+ ) ) ) )
440443 }
441444}
442445
443446#[ cfg( feature = "alloc" ) ]
444447impl < T : TryInto < ScVal > + Clone > TryFrom < & [ T ] > for ScVal {
445448 type Error = ( ) ;
446449 fn try_from ( v : & [ T ] ) -> Result < Self , ( ) > {
447- Ok ( ScVal :: Vec ( Some (
450+ Ok ( ScVal :: Vec ( Some ( Box :: new (
448451 v. iter ( )
449452 . map ( |t| <_ as TryInto < ScVal > >:: try_into ( t. clone ( ) ) )
450453 . collect :: < Result < Vec < _ > , _ > > ( ) // TODO: Impl conversion from Iterator to VecM in generated code.
451454 . map_err ( |_| ( ) ) ?
452455 . try_into ( )
453456 . map_err ( |_| ( ) ) ?,
454- ) ) )
457+ ) ) ) )
455458 }
456459}
457460
@@ -469,23 +472,26 @@ impl<T: TryFrom<ScVal> + Clone> TryFrom<ScVal> for Vec<T> {
469472 }
470473}
471474
475+ #[ cfg( feature = "alloc" ) ]
472476impl From < ScMap > for ScVal {
473477 fn from ( v : ScMap ) -> Self {
474- ScVal :: Map ( Some ( v ) )
478+ ScVal :: Map ( Some ( Box :: new ( v ) ) )
475479 }
476480}
477481
482+ #[ cfg( feature = "alloc" ) ]
478483impl TryFrom < ScVal > for ScMap {
479484 type Error = ( ) ;
480485 fn try_from ( v : ScVal ) -> Result < Self , Self :: Error > {
481486 if let ScVal :: Map ( Some ( m) ) = v {
482- Ok ( m)
487+ Ok ( * m)
483488 } else {
484489 Err ( ( ) )
485490 }
486491 }
487492}
488493
494+ #[ cfg( feature = "alloc" ) ]
489495impl < K , V > TryFrom < ( K , V ) > for ScMapEntry
490496where
491497 K : TryInto < ScVal > ,
@@ -495,8 +501,8 @@ where
495501
496502 fn try_from ( v : ( K , V ) ) -> Result < Self , Self :: Error > {
497503 Ok ( ScMapEntry {
498- key : v. 0 . try_into ( ) . map_err ( |_| ( ) ) ?,
499- val : v. 1 . try_into ( ) . map_err ( |_| ( ) ) ?,
504+ key : Box :: new ( v. 0 . try_into ( ) . map_err ( |_| ( ) ) ?) ,
505+ val : Box :: new ( v. 1 . try_into ( ) . map_err ( |_| ( ) ) ?) ,
500506 } )
501507 }
502508}
@@ -561,7 +567,7 @@ macro_rules! impl_for_tuple {
561567 {
562568 type Error = ( ) ;
563569 fn try_from( v: ( $( $typ, ) * ) ) -> Result <Self , ( ) > {
564- Ok ( ScVal :: Vec ( Some ( <_ as TryInto <ScVec >>:: try_into( v) ?) ) )
570+ Ok ( ScVal :: Vec ( Some ( Box :: new ( <_ as TryInto <ScVec >>:: try_into( v) ?) ) ) )
565571 }
566572 }
567573
@@ -572,10 +578,11 @@ macro_rules! impl_for_tuple {
572578 {
573579 type Error = ( ) ;
574580 fn try_from( v: & ( $( $typ, ) * ) ) -> Result <Self , ( ) > {
575- Ok ( ScVal :: Vec ( Some ( <_ as TryInto <ScVec >>:: try_into( v) ?) ) )
581+ Ok ( ScVal :: Vec ( Some ( Box :: new ( <_ as TryInto <ScVec >>:: try_into( v) ?) ) ) )
576582 }
577583 }
578584
585+ #[ cfg( feature = "alloc" ) ]
579586 impl <$( $typ) ,* > TryFrom <ScVec > for ( $( $typ, ) * )
580587 where
581588 // TODO: Consider removing the Clone constraint by changing the
@@ -598,6 +605,7 @@ macro_rules! impl_for_tuple {
598605 }
599606 }
600607
608+ #[ cfg( feature = "alloc" ) ]
601609 impl <$( $typ) ,* > TryFrom <ScVal > for ( $( $typ, ) * )
602610 where
603611 $( $typ: TryFrom <ScVal > + Clone ) ,*
@@ -606,7 +614,7 @@ macro_rules! impl_for_tuple {
606614
607615 fn try_from( obj: ScVal ) -> Result <Self , Self :: Error > {
608616 if let ScVal :: Vec ( Some ( vec) ) = obj {
609- <_ as TryFrom <ScVec >>:: try_from( vec)
617+ <_ as TryFrom <ScVec >>:: try_from( * vec)
610618 } else {
611619 Err ( ( ) )
612620 }
@@ -810,6 +818,7 @@ mod test {
810818 assert_eq ! ( val, ScVal :: Void ) ;
811819 }
812820
821+ #[ cfg( feature = "alloc" ) ]
813822 #[ test]
814823 fn scval_from ( ) {
815824 let _ = ScVal :: from ( ScVec :: default ( ) ) ;
0 commit comments