git.delta.rocks / unique-network / refs/commits / b841d6317de8

difftreelog

feat impls SolidityTypeName & SolidityStructTy for Option<T>

Trubnikov Sergey2023-01-10parent: #50ff12a.patch.diff
in: master

2 files changed

modifiedcrates/evm-coder/src/solidity/impls.rsdiffbeforeafterboth
122impl_tuples! {A B C D E F G H I}122impl_tuples! {A B C D E F G H I}
123impl_tuples! {A B C D E F G H I J}123impl_tuples! {A B C D E F G H I J}
124
125//----- impls for Option -----
126impl<T: SolidityTypeName + 'static> SolidityTypeName for Option<T> {
127 fn solidity_name(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {
128 write!(writer, "{}", tc.collect_struct::<Self>())
129 }
130 fn is_simple() -> bool {
131 false
132 }
133 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {
134 write!(writer, "{}(", tc.collect_struct::<Self>())?;
135 bool::solidity_default(writer, tc)?;
136 write!(writer, ", ");
137 T::solidity_default(writer, tc)?;
138 write!(writer, ")")
139 }
140}
141
142impl<T: SolidityTypeName> super::SolidityStructTy for Option<T> {
143 fn generate_solidity_interface(tc: &TypeCollector) -> String {
144 // use super::solidity::*;
145
146 let mut solidity_name = "Option_".to_string();
147 T::solidity_name(&mut solidity_name, tc);
148 let solidity_name_str = solidity_name.as_str();
149 let interface = super::SolidityStruct {
150 docs: &[" Optional value"],
151 name: solidity_name_str,
152 fields: (
153 super::SolidityStructField::<bool> {
154 docs: &[" Shows the status of accessibility of value"],
155 name: "status",
156 ty: ::core::marker::PhantomData,
157 },
158 super::SolidityStructField::<T> {
159 docs: &[" Actual value if `status` is true"],
160 name: "value",
161 ty: ::core::marker::PhantomData,
162 },
163 ),
164 };
165
166 let mut out = String::new();
167 let _ = interface.format(&mut out, tc);
168 tc.collect(out);
169
170 solidity_name.to_string()
171 }
172}
124173
modifiedcrates/evm-coder/src/solidity/mod.rsdiffbeforeafterboth
456 Ok(())456 Ok(())
457 }457 }
458}458}
459pub struct SolidityStruct<F> {459pub struct SolidityStruct<'a, F> {
460 pub docs: &'static [&'static str],460 pub docs: &'a [&'a str],
461 // pub generics:461 // pub generics:
462 pub name: &'static str,462 pub name: &'a str,
463 pub fields: F,463 pub fields: F,
464}464}
465impl<F> SolidityStruct<F>465impl<F> SolidityStruct<'_, F>
466where466where
467 F: SolidityItems,467 F: SolidityItems,
468{468{