@@ -116,6 +116,7 @@ pub trait Connection: Send {
116116 fn connect ( url : & str ) -> BoxFuture < ' static , Result < Self , Error > >
117117 where
118118 Self : Sized ,
119+ Self :: Options : FromStr < Err = Error > ,
119120 {
120121 let options = url. parse ( ) ;
121122
@@ -161,19 +162,28 @@ impl LogSettings {
161162pub trait ConnectOptions : Sized + Send + Sync + ' static {
162163 type Connection : Connection ;
163164
164- fn from_url ( url : & str ) -> Result < Self , Error > ;
165+ fn from_url ( url : & str ) -> Result < Self , Error >
166+ where
167+ Self : std:: str:: FromStr < Err = Error > ,
168+ {
169+ Self :: from_str ( url)
170+ }
165171
166172 fn connect ( & self ) -> BoxFuture < ' _ , Result < Self :: Connection , Error > > ;
167173
168- fn connect_with ( options : & Self ) -> BoxFuture < ' _ , Result < Self :: Connection , Error > > ;
174+ fn connect_with ( options : & Self ) -> BoxFuture < ' _ , Result < Self :: Connection , Error > > {
175+ options. connect ( )
176+ }
169177
170- fn from_env ( ) -> Result < Self , Error > {
171- let options = Self :: from_url ( & std:: env:: var ( "DATABASE_URL" ) ?) ?;
172- Box :: pin ( async move { Self :: connect_with ( & options?) . await } )
178+ fn from_env ( ) -> Result < Self , Error >
179+ where
180+ Self : std:: str:: FromStr < Err = Error > ,
181+ {
182+ let url = std:: env:: var ( "DATABASE_URL" ) . map_err ( Error :: config) ?;
183+ Self :: from_str ( & url)
173184 }
174185
175- fn create_pool (
176- & self ,
177- options : crate :: pool:: PoolOptions < Self :: Connection > ,
178- ) -> Result < crate :: pool:: Pool < Self :: Connection > , Error > ;
186+ fn log_statements ( & mut self , level : LevelFilter ) -> & mut Self ;
187+
188+ fn log_slow_statements ( & mut self , level : LevelFilter , duration : Duration ) -> & mut Self ;
179189}
0 commit comments