Skip to content

Commit bb499e5

Browse files
Deref instead of borrowing Option<&String> (pgcentralfoundation#2185)
Instances of `Option<&String>` are weird. They should be either `Option<String>` or `Option<&str>`. I chose `Option<&str>` to avoid clones.
1 parent 0047841 commit bb499e5

11 files changed

Lines changed: 28 additions & 28 deletions

File tree

cargo-pgrx/src/command/connect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl CommandExecute for Connect {
5050

5151
let (package_manifest, package_manifest_path) = get_package_manifest(
5252
&Features::default(),
53-
self.package.as_ref(),
53+
self.package.as_deref(),
5454
self.manifest_path.as_deref(),
5555
)?;
5656
let (pg_config, _pg_version) = match pg_config_and_version(

cargo-pgrx/src/command/get.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl CommandExecute for Get {
3838
.wrap_err("couldn't get cargo metadata")?;
3939
crate::metadata::validate(self.manifest_path.as_deref(), &metadata)?;
4040
let package_manifest_path =
41-
crate::manifest::manifest_path(&metadata, self.package.as_ref())
41+
crate::manifest::manifest_path(&metadata, self.package.as_deref())
4242
.wrap_err("Couldn't get manifest path")?;
4343

4444
if let Some(value) = get_property(&package_manifest_path, &self.name)? {

cargo-pgrx/src/command/install.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl CommandExecute for Install {
7575
.wrap_err("couldn't get cargo metadata")?;
7676
crate::metadata::validate(self.manifest_path.as_deref(), &metadata)?;
7777
let package_manifest_path =
78-
crate::manifest::manifest_path(&metadata, self.package.as_ref())
78+
crate::manifest::manifest_path(&metadata, self.package.as_deref())
7979
.wrap_err("Couldn't get manifest path")?;
8080
let package_manifest =
8181
Manifest::from_path(&package_manifest_path).wrap_err("Couldn't parse manifest")?;
@@ -101,7 +101,7 @@ impl CommandExecute for Install {
101101
display_version_info(&pg_config, &PgVersionSource::PgConfig(pg_config.label()?));
102102
install_extension(
103103
self.manifest_path.as_deref(),
104-
self.package.as_ref(),
104+
self.package.as_deref(),
105105
&package_manifest_path,
106106
&pg_config,
107107
&profile,
@@ -123,7 +123,7 @@ impl CommandExecute for Install {
123123
))]
124124
pub(crate) fn install_extension(
125125
user_manifest_path: Option<&Path>,
126-
user_package: Option<&String>,
126+
user_package: Option<&str>,
127127
package_manifest_path: &Path,
128128
pg_config: &PgConfig,
129129
profile: &CargoProfile,
@@ -282,7 +282,7 @@ fn copy_file(
282282

283283
pub(crate) fn build_extension(
284284
user_manifest_path: Option<&Path>,
285-
user_package: Option<&String>,
285+
user_package: Option<&str>,
286286
profile: &CargoProfile,
287287
features: &clap_cargo::Features,
288288
target: Option<&str>,
@@ -345,7 +345,7 @@ pub(crate) fn build_extension(
345345

346346
fn copy_sql_files(
347347
user_manifest_path: Option<&Path>,
348-
user_package: Option<&String>,
348+
user_package: Option<&str>,
349349
package_manifest_path: &Path,
350350
profile: &CargoProfile,
351351
is_test: bool,

cargo-pgrx/src/command/package.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Package {
5555
.wrap_err("couldn't get cargo metadata")?;
5656
crate::metadata::validate(self.manifest_path.as_deref(), &metadata)?;
5757
let package_manifest_path =
58-
crate::manifest::manifest_path(&metadata, self.package.as_ref())
58+
crate::manifest::manifest_path(&metadata, self.package.as_deref())
5959
.wrap_err("Couldn't get manifest path")?;
6060
let package_manifest =
6161
Manifest::from_path(&package_manifest_path).wrap_err("Couldn't parse manifest")?;
@@ -86,7 +86,7 @@ impl Package {
8686

8787
let output_files = package_extension(
8888
self.manifest_path.as_deref(),
89-
self.package.as_ref(),
89+
self.package.as_deref(),
9090
&package_manifest_path,
9191
&pg_config,
9292
out_dir.clone(),
@@ -115,7 +115,7 @@ impl CommandExecute for Package {
115115
))]
116116
pub(crate) fn package_extension(
117117
user_manifest_path: Option<&Path>,
118-
user_package: Option<&String>,
118+
user_package: Option<&str>,
119119
package_manifest_path: &Path,
120120
pg_config: &PgConfig,
121121
out_dir: PathBuf,

cargo-pgrx/src/command/regress.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl CommandExecute for Regress {
347347
}
348348
let (_, manifest_path) = get_package_manifest(
349349
&self.features,
350-
self.package.as_ref(),
350+
self.package.as_deref(),
351351
self.manifest_path.as_deref(),
352352
)?;
353353
let extname = get_property(&manifest_path, "extname")?

cargo-pgrx/src/command/run.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Run {
8686
let pgrx = Pgrx::from_config()?;
8787
let (package_manifest, package_manifest_path) = get_package_manifest(
8888
&self.features,
89-
self.package.as_ref(),
89+
self.package.as_deref(),
9090
self.manifest_path.as_deref(),
9191
)?;
9292
let (pg_config, _pg_version) = pg_config_and_version(
@@ -110,7 +110,7 @@ impl Run {
110110
run(
111111
&pg_config,
112112
self.manifest_path.as_deref(),
113-
self.package.as_ref(),
113+
self.package.as_deref(),
114114
&package_manifest_path,
115115
&dbname,
116116
create_database,
@@ -144,7 +144,7 @@ impl CommandExecute for Run {
144144
pub(crate) fn run(
145145
pg_config: &PgConfig,
146146
user_manifest_path: Option<&Path>,
147-
user_package: Option<&String>,
147+
user_package: Option<&str>,
148148
package_manifest_path: &Path,
149149
dbname: &str,
150150
create_database: bool,

cargo-pgrx/src/command/schema.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl CommandExecute for Schema {
7979
let pgrx = Pgrx::from_config()?;
8080
let (package_manifest, package_manifest_path) = get_package_manifest(
8181
&self.features,
82-
self.package.as_ref(),
82+
self.package.as_deref(),
8383
self.manifest_path.as_deref(),
8484
)?;
8585
// This does meaningful mutation, unfortunately
@@ -98,7 +98,7 @@ impl CommandExecute for Schema {
9898

9999
generate_schema(
100100
self.manifest_path.as_deref(),
101-
self.package.as_ref(),
101+
self.package.as_deref(),
102102
&package_manifest_path,
103103
&profile,
104104
self.test,
@@ -122,7 +122,7 @@ impl CommandExecute for Schema {
122122
))]
123123
pub(crate) fn generate_schema(
124124
user_manifest_path: Option<&Path>,
125-
user_package: Option<&String>,
125+
user_package: Option<&str>,
126126
package_manifest_path: &Path,
127127
profile: &CargoProfile,
128128
is_test: bool,
@@ -142,7 +142,7 @@ pub(crate) fn generate_schema(
142142
let features_arg = features.features.join(" ");
143143

144144
let package_name = if let Some(user_package) = user_package {
145-
user_package.clone()
145+
user_package.to_owned()
146146
} else {
147147
manifest.package_name()?
148148
};

cargo-pgrx/src/command/start.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl CommandExecute for Start {
5252
) -> eyre::Result<()> {
5353
let (package_manifest, _) = get_package_manifest(
5454
&clap_cargo::Features::default(),
55-
me.package.as_ref(),
55+
me.package.as_deref(),
5656
me.manifest_path.as_deref(),
5757
)?;
5858

@@ -63,7 +63,7 @@ impl CommandExecute for Start {
6363
}
6464
let (package_manifest, _) = get_package_manifest(
6565
&clap_cargo::Features::default(),
66-
self.package.as_ref(),
66+
self.package.as_deref(),
6767
self.manifest_path.as_deref(),
6868
)?;
6969

cargo-pgrx/src/command/stop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl CommandExecute for Stop {
3939
fn perform(me: Stop, pgrx: &Pgrx) -> eyre::Result<()> {
4040
let (package_manifest, _) = get_package_manifest(
4141
&clap_cargo::Features::default(),
42-
me.package.as_ref(),
42+
me.package.as_deref(),
4343
me.manifest_path.as_deref(),
4444
)?;
4545
let (pg_config, _) =
@@ -51,7 +51,7 @@ impl CommandExecute for Stop {
5151
let pgrx = Pgrx::from_config()?;
5252
let (package_manifest, _) = get_package_manifest(
5353
&clap_cargo::Features::default(),
54-
self.package.as_ref(),
54+
self.package.as_deref(),
5555
self.manifest_path.as_deref(),
5656
)?;
5757
if self.pg_version == Some("all".into()) {

cargo-pgrx/src/command/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl CommandExecute for Test {
6060
let mut features = me.features.clone();
6161
let (package_manifest, _package_manifest_path) = get_package_manifest(
6262
&me.features,
63-
me.package.as_ref(),
63+
me.package.as_deref(),
6464
me.manifest_path.as_deref(),
6565
)?;
6666
let (pg_config, _pg_version) = pg_config_and_version(
@@ -79,7 +79,7 @@ impl CommandExecute for Test {
7979
test_extension(
8080
&pg_config,
8181
me.manifest_path.as_deref(),
82-
me.package.as_ref(),
82+
me.package.as_deref(),
8383
&profile,
8484
me.no_schema,
8585
&features,
@@ -93,7 +93,7 @@ impl CommandExecute for Test {
9393

9494
let (package_manifest, _) = get_package_manifest(
9595
&self.features,
96-
self.package.as_ref(),
96+
self.package.as_deref(),
9797
self.manifest_path.as_deref(),
9898
)?;
9999
let pgrx = Pgrx::from_config()?;
@@ -121,7 +121,7 @@ impl CommandExecute for Test {
121121
pub fn test_extension(
122122
pg_config: &PgConfig,
123123
user_manifest_path: Option<&Path>,
124-
user_package: Option<&String>,
124+
user_package: Option<&str>,
125125
profile: &CargoProfile,
126126
no_schema: bool,
127127
features: &clap_cargo::Features,

0 commit comments

Comments
 (0)