30
30
//! io::copy(&mut large_object, &mut file).unwrap();
31
31
//! }
32
32
//! ```
33
- #![ doc( html_root_url= "https://docs.rs/postgres_large_object/0.7.0 " ) ]
33
+ #![ doc( html_root_url = "https://docs.rs/postgres_large_object/0.7" ) ]
34
34
35
35
extern crate postgres;
36
36
37
- use postgres:: { Result , GenericConnection } ;
37
+ use postgres:: { GenericConnection , Result } ;
38
38
use postgres:: transaction:: Transaction ;
39
39
use postgres:: types:: Oid ;
40
40
use std:: cmp;
@@ -150,25 +150,21 @@ impl<'a> LargeObject<'a> {
150
150
/// null bytes to the specified size.
151
151
pub fn truncate ( & mut self , len : i64 ) -> Result < ( ) > {
152
152
if self . has_64 {
153
- let stmt = self . trans . prepare_cached (
154
- "SELECT pg_catalog.lo_truncate64($1, $2)" ,
155
- ) ?;
153
+ let stmt = self . trans
154
+ . prepare_cached ( "SELECT pg_catalog.lo_truncate64($1, $2)" ) ?;
156
155
stmt. execute ( & [ & self . fd , & len] ) . map ( |_| ( ) )
157
156
} else {
158
157
let len = if len <= i32:: max_value ( ) as i64 {
159
158
len as i32
160
159
} else {
161
- return Err (
162
- io:: Error :: new (
163
- io:: ErrorKind :: InvalidInput ,
164
- "The database does not support objects larger \
165
- than 2GB",
166
- ) . into ( ) ,
167
- ) ;
160
+ return Err ( io:: Error :: new (
161
+ io:: ErrorKind :: InvalidInput ,
162
+ "The database does not support objects larger \
163
+ than 2GB",
164
+ ) . into ( ) ) ;
168
165
} ;
169
- let stmt = self . trans . prepare_cached (
170
- "SELECT pg_catalog.lo_truncate($1, $2)" ,
171
- ) ?;
166
+ let stmt = self . trans
167
+ . prepare_cached ( "SELECT pg_catalog.lo_truncate($1, $2)" ) ?;
172
168
stmt. execute ( & [ & self . fd , & len] ) . map ( |_| ( ) )
173
169
}
174
170
}
@@ -194,9 +190,8 @@ impl<'a> LargeObject<'a> {
194
190
195
191
impl < ' a > io:: Read for LargeObject < ' a > {
196
192
fn read ( & mut self , mut buf : & mut [ u8 ] ) -> io:: Result < usize > {
197
- let stmt = self . trans . prepare_cached (
198
- "SELECT pg_catalog.loread($1, $2)" ,
199
- ) ?;
193
+ let stmt = self . trans
194
+ . prepare_cached ( "SELECT pg_catalog.loread($1, $2)" ) ?;
200
195
let cap = cmp:: min ( buf. len ( ) , i32:: MAX as usize ) as i32 ;
201
196
let rows = stmt. query ( & [ & self . fd , & cap] ) ?;
202
197
buf. write ( rows. get ( 0 ) . get_bytes ( 0 ) . unwrap ( ) )
@@ -205,9 +200,8 @@ impl<'a> io::Read for LargeObject<'a> {
205
200
206
201
impl < ' a > io:: Write for LargeObject < ' a > {
207
202
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
208
- let stmt = self . trans . prepare_cached (
209
- "SELECT pg_catalog.lowrite($1, $2)" ,
210
- ) ?;
203
+ let stmt = self . trans
204
+ . prepare_cached ( "SELECT pg_catalog.lowrite($1, $2)" ) ?;
211
205
let cap = cmp:: min ( buf. len ( ) , i32:: MAX as usize ) ;
212
206
stmt. execute ( & [ & self . fd , & & buf[ ..cap] ] ) ?;
213
207
Ok ( cap)
@@ -237,9 +231,8 @@ impl<'a> io::Seek for LargeObject<'a> {
237
231
} ;
238
232
239
233
if self . has_64 {
240
- let stmt = self . trans . prepare_cached (
241
- "SELECT pg_catalog.lo_lseek64($1, $2, $3)" ,
242
- ) ?;
234
+ let stmt = self . trans
235
+ . prepare_cached ( "SELECT pg_catalog.lo_lseek64($1, $2, $3)" ) ?;
243
236
let rows = stmt. query ( & [ & self . fd , & pos, & kind] ) ?;
244
237
let pos: i64 = rows. iter ( ) . next ( ) . unwrap ( ) . get ( 0 ) ;
245
238
Ok ( pos as u64 )
@@ -252,9 +245,8 @@ impl<'a> io::Seek for LargeObject<'a> {
252
245
"cannot seek more than 2^31 bytes" ,
253
246
) ) ;
254
247
} ;
255
- let stmt = self . trans . prepare_cached (
256
- "SELECT pg_catalog.lo_lseek($1, $2, $3)" ,
257
- ) ?;
248
+ let stmt = self . trans
249
+ . prepare_cached ( "SELECT pg_catalog.lo_lseek($1, $2, $3)" ) ?;
258
250
let rows = stmt. query ( & [ & self . fd , & pos, & kind] ) ?;
259
251
let pos: i32 = rows. iter ( ) . next ( ) . unwrap ( ) . get ( 0 ) ;
260
252
Ok ( pos as u64 )
@@ -275,7 +267,7 @@ mod test {
275
267
use postgres:: { Connection , TlsMode } ;
276
268
use postgres:: error:: UNDEFINED_OBJECT ;
277
269
278
- use { LargeObjectExt , LargeObjectTransactionExt , Mode , parse_version } ;
270
+ use { parse_version , LargeObjectExt , LargeObjectTransactionExt , Mode } ;
279
271
280
272
#[ test]
281
273
fn test_create_delete ( ) {
@@ -316,7 +308,7 @@ mod test {
316
308
317
309
#[ test]
318
310
fn test_write_read ( ) {
319
- use std:: io:: { Write , Read } ;
311
+ use std:: io:: { Read , Write } ;
320
312
321
313
let conn = Connection :: connect ( "postgres://postgres@localhost" , TlsMode :: None ) . unwrap ( ) ;
322
314
let trans = conn. transaction ( ) . unwrap ( ) ;
@@ -331,7 +323,7 @@ mod test {
331
323
332
324
#[ test]
333
325
fn test_seek_tell ( ) {
334
- use std:: io:: { Write , Read , Seek , SeekFrom } ;
326
+ use std:: io:: { Read , Seek , SeekFrom , Write } ;
335
327
336
328
let conn = Connection :: connect ( "postgres://postgres@localhost" , TlsMode :: None ) . unwrap ( ) ;
337
329
let trans = conn. transaction ( ) . unwrap ( ) ;
@@ -366,7 +358,7 @@ mod test {
366
358
367
359
#[ test]
368
360
fn test_truncate ( ) {
369
- use std:: io:: { Seek , SeekFrom , Write , Read } ;
361
+ use std:: io:: { Read , Seek , SeekFrom , Write } ;
370
362
371
363
let conn = Connection :: connect ( "postgres://postgres@localhost" , TlsMode :: None ) . unwrap ( ) ;
372
364
let trans = conn. transaction ( ) . unwrap ( ) ;
0 commit comments