Skip to content

Commit a454378

Browse files
committed
Restore back compat
1 parent f777f74 commit a454378

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

postgres/src/config.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,12 @@ impl Config {
150150
}
151151

152152
/// Gets the user to authenticate with.
153+
///
153154
/// If no user has been configured with the [`user`](Config::user) method,
154-
/// then this defaults to the user executing this process.
155-
pub fn get_user(&self) -> &str {
155+
/// then this defaults to the user executing this process. It always
156+
/// returns `Some`.
157+
// FIXME remove option
158+
pub fn get_user(&self) -> Option<&str> {
156159
self.config.get_user()
157160
}
158161

tokio-postgres/src/config.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub enum Host {
190190
/// ```
191191
#[derive(Clone, PartialEq, Eq)]
192192
pub struct Config {
193-
user: String,
193+
pub(crate) user: String,
194194
pub(crate) password: Option<Vec<u8>>,
195195
pub(crate) dbname: Option<String>,
196196
pub(crate) options: Option<String>,
@@ -245,17 +245,20 @@ impl Config {
245245

246246
/// Sets the user to authenticate with.
247247
///
248-
/// If the user is not set, then this defaults to the user executing this process.
248+
/// Defaults to the user executing this process.
249249
pub fn user(&mut self, user: &str) -> &mut Config {
250250
self.user = user.to_string();
251251
self
252252
}
253253

254254
/// Gets the user to authenticate with.
255+
///
255256
/// If no user has been configured with the [`user`](Config::user) method,
256-
/// then this defaults to the user executing this process.
257-
pub fn get_user(&self) -> &str {
258-
&self.user
257+
/// then this defaults to the user executing this process. It always
258+
/// returns `Some`.
259+
// FIXME remove option
260+
pub fn get_user(&self) -> Option<&str> {
261+
Some(&self.user)
259262
}
260263

261264
/// Sets the password to authenticate with.
@@ -1125,7 +1128,7 @@ mod tests {
11251128
fn test_simple_parsing() {
11261129
let s = "user=pass_user dbname=postgres host=host1,host2 hostaddr=127.0.0.1,127.0.0.2 port=26257";
11271130
let config = s.parse::<Config>().unwrap();
1128-
assert_eq!("pass_user", config.get_user());
1131+
assert_eq!(Some("pass_user"), config.get_user());
11291132
assert_eq!(Some("postgres"), config.get_dbname());
11301133
assert_eq!(
11311134
[

tokio-postgres/src/connect_raw.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ where
113113
T: AsyncRead + AsyncWrite + Unpin,
114114
{
115115
let mut params = vec![("client_encoding", "UTF8")];
116-
params.push(("user", config.get_user()));
116+
params.push(("user", &config.user));
117117
if let Some(dbname) = &config.dbname {
118118
params.push(("database", &**dbname));
119119
}
@@ -156,7 +156,7 @@ where
156156
Some(Message::AuthenticationMd5Password(body)) => {
157157
can_skip_channel_binding(config)?;
158158

159-
let user = config.get_user();
159+
let user = &config.user;
160160
let pass = config
161161
.password
162162
.as_ref()

0 commit comments

Comments
 (0)