File tree Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -613,7 +613,41 @@ impl_for_parseable!(
613
613
i128 ,
614
614
isize ,
615
615
url:: Url ,
616
- tracing:: Level ,
616
+ tracing:: Level
617
+ ) ;
618
+
619
+ /// EnvItemInfo for .env variable holding chain name
620
+ /// Used to implement FromEnv for SignetConstants type structs
621
+ /// that can be instantiated from a single chain name
622
+ static CHAIN_NAME : EnvItemInfo = EnvItemInfo {
623
+ var : "CHAIN_NAME" ,
624
+ description : "The name of the chain, e.g. `pecorino`" ,
625
+ optional : false ,
626
+ } ;
627
+
628
+ macro_rules! impl_from_chain {
629
+ ( $( $t: ty) ,* ) => {
630
+ $(
631
+ // first, impl FromEnvVar for the type
632
+ impl_for_parseable!( $t) ;
633
+
634
+ // next, impl FromEnv using FromEnvVar using the CHAIN_NAME env var
635
+ impl FromEnv for $t {
636
+ type Error = <$t as FromStr >:: Err ;
637
+
638
+ fn inventory( ) -> Vec <& ' static EnvItemInfo > {
639
+ vec![ & CHAIN_NAME ]
640
+ }
641
+
642
+ fn from_env( ) -> Result <Self , FromEnvErr <Self :: Error >> {
643
+ Self :: from_env_var( CHAIN_NAME . var)
644
+ }
645
+ }
646
+ ) *
647
+ }
648
+ }
649
+
650
+ impl_from_chain ! (
617
651
SignetConstants ,
618
652
SignetEnvironmentConstants ,
619
653
SignetSystemConstants ,
You can’t perform that action at this time.
0 commit comments