@@ -841,13 +841,11 @@ fn _ensure_send() {
841
841
}
842
842
843
843
/// A connection to a Postgres database.
844
- pub struct Connection {
845
- conn : RefCell < InnerConnection > ,
846
- }
844
+ pub struct Connection ( RefCell < InnerConnection > ) ;
847
845
848
846
impl fmt:: Debug for Connection {
849
847
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
850
- let conn = self . conn . borrow ( ) ;
848
+ let conn = self . 0 . borrow ( ) ;
851
849
fmt. debug_struct ( "Connection" )
852
850
. field ( "stream" , & conn. stream . get_ref ( ) )
853
851
. field ( "cancel_data" , & conn. cancel_data )
@@ -919,7 +917,7 @@ impl Connection {
919
917
pub fn connect < T > ( params : T , tls : TlsMode ) -> result:: Result < Connection , ConnectError >
920
918
where T : IntoConnectParams
921
919
{
922
- InnerConnection :: connect ( params, tls) . map ( |conn| Connection { conn : RefCell :: new ( conn) } )
920
+ InnerConnection :: connect ( params, tls) . map ( |conn| Connection ( RefCell :: new ( conn) ) )
923
921
}
924
922
925
923
/// Executes a statement, returning the number of rows modified.
@@ -950,7 +948,7 @@ impl Connection {
950
948
/// println!("{} rows updated", rows_updated);
951
949
/// ```
952
950
pub fn execute ( & self , query : & str , params : & [ & ToSql ] ) -> Result < u64 > {
953
- let ( param_types, columns) = try!( self . conn . borrow_mut ( ) . raw_prepare ( "" , query) ) ;
951
+ let ( param_types, columns) = try!( self . 0 . borrow_mut ( ) . raw_prepare ( "" , query) ) ;
954
952
let info = Arc :: new ( StatementInfo {
955
953
name : String :: new ( ) ,
956
954
param_types : param_types,
@@ -986,7 +984,7 @@ impl Connection {
986
984
/// }
987
985
/// ```
988
986
pub fn query < ' a > ( & ' a self , query : & str , params : & [ & ToSql ] ) -> Result < Rows < ' a > > {
989
- let ( param_types, columns) = try!( self . conn . borrow_mut ( ) . raw_prepare ( "" , query) ) ;
987
+ let ( param_types, columns) = try!( self . 0 . borrow_mut ( ) . raw_prepare ( "" , query) ) ;
990
988
let info = Arc :: new ( StatementInfo {
991
989
name : String :: new ( ) ,
992
990
param_types : param_types,
@@ -1027,7 +1025,7 @@ impl Connection {
1027
1025
1028
1026
/// Begins a new transaction with the specified configuration.
1029
1027
pub fn transaction_with < ' a > ( & ' a self , config : & transaction:: Config ) -> Result < Transaction < ' a > > {
1030
- let mut conn = self . conn . borrow_mut ( ) ;
1028
+ let mut conn = self . 0 . borrow_mut ( ) ;
1031
1029
check_desync ! ( conn) ;
1032
1030
assert ! ( conn. trans_depth == 0 ,
1033
1031
"`transaction` must be called on the active transaction" ) ;
@@ -1060,7 +1058,7 @@ impl Connection {
1060
1058
/// }
1061
1059
/// ```
1062
1060
pub fn prepare < ' a > ( & ' a self , query : & str ) -> Result < Statement < ' a > > {
1063
- self . conn . borrow_mut ( ) . prepare ( query, self )
1061
+ self . 0 . borrow_mut ( ) . prepare ( query, self )
1064
1062
}
1065
1063
1066
1064
/// Creates a cached prepared statement.
@@ -1084,14 +1082,14 @@ impl Connection {
1084
1082
/// }
1085
1083
/// ```
1086
1084
pub fn prepare_cached < ' a > ( & ' a self , query : & str ) -> Result < Statement < ' a > > {
1087
- self . conn . borrow_mut ( ) . prepare_cached ( query, self )
1085
+ self . 0 . borrow_mut ( ) . prepare_cached ( query, self )
1088
1086
}
1089
1087
1090
1088
/// Returns the isolation level which will be used for future transactions.
1091
1089
///
1092
1090
/// This is a simple wrapper around `SHOW TRANSACTION ISOLATION LEVEL`.
1093
1091
pub fn transaction_isolation ( & self ) -> Result < IsolationLevel > {
1094
- let mut conn = self . conn . borrow_mut ( ) ;
1092
+ let mut conn = self . 0 . borrow_mut ( ) ;
1095
1093
check_desync ! ( conn) ;
1096
1094
let result = try!( conn. quick_query ( "SHOW TRANSACTION ISOLATION LEVEL" ) ) ;
1097
1095
IsolationLevel :: new ( result[ 0 ] [ 0 ] . as_ref ( ) . unwrap ( ) )
@@ -1139,7 +1137,7 @@ impl Connection {
1139
1137
/// ").unwrap();
1140
1138
/// ```
1141
1139
pub fn batch_execute ( & self , query : & str ) -> Result < ( ) > {
1142
- self . conn . borrow_mut ( ) . quick_query ( query) . map ( |_| ( ) )
1140
+ self . 0 . borrow_mut ( ) . quick_query ( query) . map ( |_| ( ) )
1143
1141
}
1144
1142
1145
1143
/// Returns a structure providing access to asynchronous notifications.
@@ -1154,18 +1152,18 @@ impl Connection {
1154
1152
/// Used with the `cancel_query` function. The object returned can be used
1155
1153
/// to cancel any query executed by the connection it was created from.
1156
1154
pub fn cancel_data ( & self ) -> CancelData {
1157
- self . conn . borrow ( ) . cancel_data
1155
+ self . 0 . borrow ( ) . cancel_data
1158
1156
}
1159
1157
1160
1158
/// Returns the value of the specified Postgres backend parameter, such as
1161
1159
/// `timezone` or `server_version`.
1162
1160
pub fn parameter ( & self , param : & str ) -> Option < String > {
1163
- self . conn . borrow ( ) . parameters . get ( param) . cloned ( )
1161
+ self . 0 . borrow ( ) . parameters . get ( param) . cloned ( )
1164
1162
}
1165
1163
1166
1164
/// Sets the notice handler for the connection, returning the old handler.
1167
1165
pub fn set_notice_handler ( & self , handler : Box < HandleNotice > ) -> Box < HandleNotice > {
1168
- self . conn . borrow_mut ( ) . set_notice_handler ( handler)
1166
+ self . 0 . borrow_mut ( ) . set_notice_handler ( handler)
1169
1167
}
1170
1168
1171
1169
/// Returns whether or not the stream has been desynchronized due to an
@@ -1174,7 +1172,7 @@ impl Connection {
1174
1172
/// If this has occurred, all further queries will immediately return an
1175
1173
/// error.
1176
1174
pub fn is_desynchronized ( & self ) -> bool {
1177
- self . conn . borrow ( ) . is_desynchronized ( )
1175
+ self . 0 . borrow ( ) . is_desynchronized ( )
1178
1176
}
1179
1177
1180
1178
/// Determines if the `Connection` is currently "active", that is, if there
@@ -1183,15 +1181,15 @@ impl Connection {
1183
1181
/// The `transaction` method can only be called on the active `Connection`
1184
1182
/// or `Transaction`.
1185
1183
pub fn is_active ( & self ) -> bool {
1186
- self . conn . borrow ( ) . trans_depth == 0
1184
+ self . 0 . borrow ( ) . trans_depth == 0
1187
1185
}
1188
1186
1189
1187
/// Consumes the connection, closing it.
1190
1188
///
1191
1189
/// Functionally equivalent to the `Drop` implementation for `Connection`
1192
1190
/// except that it returns any error encountered to the caller.
1193
1191
pub fn finish ( self ) -> Result < ( ) > {
1194
- let mut conn = self . conn . borrow_mut ( ) ;
1192
+ let mut conn = self . 0 . borrow_mut ( ) ;
1195
1193
conn. finished = true ;
1196
1194
conn. finish_inner ( )
1197
1195
}
0 commit comments