@@ -23,7 +23,7 @@ struct AssociationSite<A> {
2323 parameters : A ,
2424}
2525
26- impl < A > AssociationSite < A > {
26+ impl < A : Clone + Default > AssociationSite < A > {
2727 fn new ( assoc_comp : usize , site_index : usize , n : f64 , parameters : A ) -> Self {
2828 Self {
2929 assoc_comp,
@@ -53,7 +53,7 @@ pub struct AssociationRecord<A> {
5353 pub nc : f64 ,
5454}
5555
56- impl < A > AssociationRecord < A > {
56+ impl < A : Clone + Default > AssociationRecord < A > {
5757 pub fn new ( parameters : A , na : f64 , nb : f64 , nc : f64 ) -> Self {
5858 Self {
5959 parameters,
@@ -81,29 +81,22 @@ impl<A: fmt::Display> fmt::Display for AssociationRecord<A> {
8181}
8282
8383#[ derive( Clone , Serialize , Deserialize , Default ) ]
84- #[ serde( from = "AssociationRecordsSerde" ) ]
85- #[ serde( into = "AssociationRecordsSerde" ) ]
86- pub struct AssociationRecords ( Vec < AssociationRecord > ) ;
84+ #[ serde( from = "AssociationRecordsSerde<A> " ) ]
85+ #[ serde( into = "AssociationRecordsSerde<A> " ) ]
86+ pub struct AssociationRecords < A : Clone + Default > ( Vec < AssociationRecord < A > > ) ;
8787
88- impl AssociationRecords {
88+ impl < A : Clone + Default > AssociationRecords < A > {
8989 pub fn new (
90- kappa_ab : Option < f64 > ,
91- epsilon_k_ab : Option < f64 > ,
90+ parameters : Option < A > ,
9291 na : Option < f64 > ,
9392 nb : Option < f64 > ,
9493 nc : Option < f64 > ,
95- association_records : Option < Vec < AssociationRecord > > ,
94+ association_records : Option < Vec < AssociationRecord < A > > > ,
9695 ) -> Self {
9796 let mut association_records = association_records. unwrap_or_default ( ) ;
98- if kappa_ab. is_some ( )
99- || epsilon_k_ab. is_some ( )
100- || na. is_some ( )
101- || nb. is_some ( )
102- || nc. is_some ( )
103- {
97+ if let Some ( parameters) = parameters {
10498 association_records. push ( AssociationRecord :: new (
105- kappa_ab. unwrap_or_default ( ) ,
106- epsilon_k_ab. unwrap_or_default ( ) ,
99+ parameters,
107100 na. unwrap_or_default ( ) ,
108101 nb. unwrap_or_default ( ) ,
109102 nc. unwrap_or_default ( ) ,
@@ -113,27 +106,27 @@ impl AssociationRecords {
113106 }
114107}
115108
116- impl Deref for AssociationRecords {
117- type Target = Vec < AssociationRecord > ;
109+ impl < A : Clone + Default > Deref for AssociationRecords < A > {
110+ type Target = Vec < AssociationRecord < A > > ;
118111
119- fn deref ( & self ) -> & Vec < AssociationRecord > {
112+ fn deref ( & self ) -> & Vec < AssociationRecord < A > > {
120113 & self . 0
121114 }
122115}
123116
124- impl DerefMut for AssociationRecords {
125- fn deref_mut ( & mut self ) -> & mut Vec < AssociationRecord > {
117+ impl < A : Clone + Default > DerefMut for AssociationRecords < A > {
118+ fn deref_mut ( & mut self ) -> & mut Vec < AssociationRecord < A > > {
126119 & mut self . 0
127120 }
128121}
129122
130- impl FromIterator < AssociationRecord > for AssociationRecords {
131- fn from_iter < T : IntoIterator < Item = AssociationRecord > > ( iter : T ) -> Self {
123+ impl < A : Clone + Default > FromIterator < AssociationRecord < A > > for AssociationRecords < A > {
124+ fn from_iter < T : IntoIterator < Item = AssociationRecord < A > > > ( iter : T ) -> Self {
132125 Self ( Vec :: from_iter ( iter) )
133126 }
134127}
135128
136- impl fmt:: Display for AssociationRecords {
129+ impl < A : Clone + Default + fmt:: Display > fmt :: Display for AssociationRecords < A > {
137130 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
138131 write ! ( f, "[" ) ?;
139132 for ( i, record) in self . 0 . iter ( ) . enumerate ( ) {
@@ -147,16 +140,16 @@ impl fmt::Display for AssociationRecords {
147140}
148141
149142#[ derive( Serialize , Deserialize ) ]
150- struct AssociationRecordsSerde {
143+ struct AssociationRecordsSerde < A > {
151144 #[ serde( flatten) ]
152- single : Option < AssociationRecord > ,
145+ single : Option < AssociationRecord < A > > ,
153146 #[ serde( default ) ]
154147 #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
155- association_records : Vec < AssociationRecord > ,
148+ association_records : Vec < AssociationRecord < A > > ,
156149}
157150
158- impl From < AssociationRecordsSerde > for AssociationRecords {
159- fn from ( value : AssociationRecordsSerde ) -> Self {
151+ impl < A : Clone + Default > From < AssociationRecordsSerde < A > > for AssociationRecords < A > {
152+ fn from ( value : AssociationRecordsSerde < A > ) -> Self {
160153 let mut association_records = value. association_records ;
161154 if let Some ( record) = value. single {
162155 association_records. push ( record) ;
@@ -165,8 +158,8 @@ impl From<AssociationRecordsSerde> for AssociationRecords {
165158 }
166159}
167160
168- impl From < AssociationRecords > for AssociationRecordsSerde {
169- fn from ( value : AssociationRecords ) -> Self {
161+ impl < A : Clone + Default > From < AssociationRecords < A > > for AssociationRecordsSerde < A > {
162+ fn from ( value : AssociationRecords < A > ) -> Self {
170163 let mut association_records = value. 0 ;
171164 let single = if association_records. len ( ) == 1 {
172165 association_records. pop ( )
@@ -336,7 +329,7 @@ impl<P: AssociationStrength> Association<P> {
336329}
337330
338331pub trait AssociationStrength : HardSphereProperties {
339- type Record : Copy ;
332+ type Record : Copy + Default ;
340333 type BinaryRecord : Copy ;
341334
342335 fn association_strength < D : DualNum < f64 > + Copy > (
0 commit comments