Skip to content

Commit aed4975

Browse files
committed
use asserts rather than awkward error checks.
1 parent a3d0733 commit aed4975

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

tokio-postgres/src/replication_client.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use pin_project_lite::pin_project;
1010
use postgres_protocol::escape::{escape_identifier, escape_literal};
1111
use postgres_protocol::message::backend::{Message, ReplicationMessage};
1212
use postgres_protocol::message::frontend;
13-
use std::io;
1413
use std::marker::PhantomPinned;
1514
use std::pin::Pin;
1615
use std::str::from_utf8;
@@ -76,18 +75,12 @@ impl ReplicationClient {
7675
let fields = rowdesc.fields().collect::<Vec<_>>().map_err(Error::parse)?;
7776
let ranges = datarow.ranges().collect::<Vec<_>>().map_err(Error::parse)?;
7877

79-
if fields.len() != 4
80-
|| fields[0].type_oid() != Type::TEXT.oid()
81-
|| fields[1].type_oid() != Type::INT4.oid()
82-
|| fields[2].type_oid() != Type::TEXT.oid()
83-
|| fields[3].type_oid() != Type::TEXT.oid()
84-
|| ranges.len() != 4
85-
{
86-
return Err(Error::parse(io::Error::new(
87-
io::ErrorKind::InvalidInput,
88-
"expected (text, int4, text, text) result",
89-
)));
90-
};
78+
assert_eq!(fields.len(), 4);
79+
assert_eq!(fields[0].type_oid(), Type::TEXT.oid());
80+
assert_eq!(fields[1].type_oid(), Type::INT4.oid());
81+
assert_eq!(fields[2].type_oid(), Type::TEXT.oid());
82+
assert_eq!(fields[3].type_oid(), Type::TEXT.oid());
83+
assert_eq!(ranges.len(), 4);
9184

9285
let values: Vec<Option<&str>> = ranges
9386
.iter()
@@ -133,12 +126,9 @@ impl ReplicationClient {
133126
let fields = rowdesc.fields().collect::<Vec<_>>().map_err(Error::parse)?;
134127
let ranges = datarow.ranges().collect::<Vec<_>>().map_err(Error::parse)?;
135128

136-
if fields.len() != 1 || fields[0].type_oid() != Type::TEXT.oid() || ranges.len() != 1 {
137-
return Err(Error::parse(io::Error::new(
138-
io::ErrorKind::InvalidInput,
139-
"expected single text column in response",
140-
)));
141-
};
129+
assert_eq!(fields.len(), 1);
130+
assert_eq!(fields[0].type_oid(), Type::TEXT.oid());
131+
assert_eq!(ranges.len(), 1);
142132

143133
let val = from_utf8(&datarow.buffer()[ranges[0].to_owned().unwrap()]).unwrap();
144134

0 commit comments

Comments
 (0)