Skip to content

Commit 2c76c06

Browse files
o2shspenserblack
andauthored
use Option<&T> instead of &Option<T> (#1338)
* init * Update src/ui/mod.rs Co-authored-by: Spenser Black <spenserblack01@gmail.com> * Update src/ui/mod.rs Co-authored-by: Spenser Black <spenserblack01@gmail.com> --------- Co-authored-by: Spenser Black <spenserblack01@gmail.com>
1 parent 89f1943 commit 2c76c06

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

src/info/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ pub fn build_info(cli_options: &CliOptions) -> Result<Info> {
162162
};
163163
let dominant_language = langs::get_main_language(&loc_by_language);
164164
let ascii_colors = get_ascii_colors(
165-
&cli_options.ascii.ascii_language,
165+
cli_options.ascii.ascii_language.as_ref(),
166166
&dominant_language,
167167
&cli_options.ascii.ascii_colors,
168168
true_color,
@@ -180,19 +180,19 @@ pub fn build_info(cli_options: &CliOptions) -> Result<Info> {
180180

181181
Ok(InfoBuilder::new(cli_options)
182182
.title(&repo, no_bold, &text_colors)
183-
.project(&repo, &repo_url, &manifest, number_separator)?
184-
.description(&manifest)
183+
.project(&repo, &repo_url, manifest.as_ref(), number_separator)?
184+
.description(manifest.as_ref())
185185
.head(&repo)?
186186
.pending(&repo)?
187-
.version(&repo, &manifest)?
187+
.version(&repo, manifest.as_ref())?
188188
.created(&git_metrics, iso_time)
189189
.languages(
190190
&loc_by_language,
191191
true_color,
192192
number_of_languages_to_display,
193193
&text_colors,
194194
)
195-
.dependencies(&manifest, number_separator)
195+
.dependencies(manifest.as_ref(), number_separator)
196196
.authors(
197197
&git_metrics,
198198
number_of_authors_to_display,
@@ -211,7 +211,7 @@ pub fn build_info(cli_options: &CliOptions) -> Result<Info> {
211211
)?
212212
.loc(&loc_by_language, number_separator)
213213
.size(&repo, number_separator)
214-
.license(&repo_path, &manifest)?
214+
.license(&repo_path, manifest.as_ref())?
215215
.build(cli_options, text_colors, dominant_language, ascii_colors))
216216
}
217217

@@ -239,9 +239,9 @@ impl InfoBuilder {
239239
self
240240
}
241241

242-
fn description(mut self, manifest: &Option<Manifest>) -> Self {
242+
fn description(mut self, manifest: Option<&Manifest>) -> Self {
243243
if !self.disabled_fields.contains(&InfoType::Description) {
244-
let description = DescriptionInfo::new(manifest.as_ref());
244+
let description = DescriptionInfo::new(manifest);
245245
self.info_fields.push(Box::new(description));
246246
}
247247
self
@@ -267,11 +267,11 @@ impl InfoBuilder {
267267
mut self,
268268
repo: &Repository,
269269
repo_url: &str,
270-
manifest: &Option<Manifest>,
270+
manifest: Option<&Manifest>,
271271
number_separator: NumberSeparator,
272272
) -> Result<Self> {
273273
if !self.disabled_fields.contains(&InfoType::Project) {
274-
let project = ProjectInfo::new(repo, repo_url, manifest.as_ref(), number_separator)?;
274+
let project = ProjectInfo::new(repo, repo_url, manifest, number_separator)?;
275275
self.info_fields.push(Box::new(project));
276276
}
277277
Ok(self)
@@ -285,9 +285,9 @@ impl InfoBuilder {
285285
Ok(self)
286286
}
287287

288-
fn version(mut self, repo: &Repository, manifest: &Option<Manifest>) -> Result<Self> {
288+
fn version(mut self, repo: &Repository, manifest: Option<&Manifest>) -> Result<Self> {
289289
if !self.disabled_fields.contains(&InfoType::Version) {
290-
let version = VersionInfo::new(repo, manifest.as_ref())?;
290+
let version = VersionInfo::new(repo, manifest)?;
291291
self.info_fields.push(Box::new(version));
292292
}
293293
Ok(self)
@@ -301,9 +301,9 @@ impl InfoBuilder {
301301
self
302302
}
303303

304-
fn license(mut self, repo_path: &Path, manifest: &Option<Manifest>) -> Result<Self> {
304+
fn license(mut self, repo_path: &Path, manifest: Option<&Manifest>) -> Result<Self> {
305305
if !self.disabled_fields.contains(&InfoType::License) {
306-
let license = LicenseInfo::new(repo_path, manifest.as_ref())?;
306+
let license = LicenseInfo::new(repo_path, manifest)?;
307307
self.info_fields.push(Box::new(license));
308308
}
309309
Ok(self)
@@ -338,11 +338,11 @@ impl InfoBuilder {
338338

339339
fn dependencies(
340340
mut self,
341-
manifest: &Option<Manifest>,
341+
manifest: Option<&Manifest>,
342342
number_separator: NumberSeparator,
343343
) -> Self {
344344
if !self.disabled_fields.contains(&InfoType::Dependencies) {
345-
let dependencies = DependenciesInfo::new(manifest.as_ref(), number_separator);
345+
let dependencies = DependenciesInfo::new(manifest, number_separator);
346346
self.info_fields.push(Box::new(dependencies));
347347
}
348348
self

src/ui/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub mod printer;
55
pub mod text_colors;
66

77
pub fn get_ascii_colors(
8-
ascii_language: &Option<Language>,
8+
ascii_language: Option<&Language>,
99
dominant_language: &Language,
1010
ascii_colors: &[u8],
1111
true_color: bool,
@@ -65,7 +65,7 @@ mod test {
6565

6666
#[test]
6767
fn get_ascii_colors_no_custom_language_no_custom_colors_no_true_color() {
68-
let colors = get_ascii_colors(&None, &Language::Rust, &[], false);
68+
let colors = get_ascii_colors(None.as_ref(), &Language::Rust, &[], false);
6969
assert_eq!(colors.len(), 2);
7070
assert_eq!(
7171
colors,
@@ -78,7 +78,7 @@ mod test {
7878

7979
#[test]
8080
fn get_ascii_colors_no_custom_language_no_custom_colors_true_color() {
81-
let colors = get_ascii_colors(&None, &Language::Rust, &[], true);
81+
let colors = get_ascii_colors(None, &Language::Rust, &[], true);
8282
assert_eq!(colors.len(), 2);
8383
assert_eq!(
8484
colors,
@@ -88,14 +88,14 @@ mod test {
8888

8989
#[test]
9090
fn get_ascii_colors_custom_language_no_custom_colors_no_true_color() {
91-
let colors = get_ascii_colors(&Some(Language::Sh), &Language::Rust, &[], false);
91+
let colors = get_ascii_colors(Some(&Language::Sh), &Language::Rust, &[], false);
9292
assert_eq!(colors.len(), 1);
9393
assert_eq!(colors, vec![DynColors::Ansi(AnsiColors::Green)]);
9494
}
9595

9696
#[test]
9797
fn get_ascii_colors_no_custom_language_custom_colors_no_true_color() {
98-
let colors = get_ascii_colors(&None, &Language::Rust, &[2, 3], false);
98+
let colors = get_ascii_colors(None.as_ref(), &Language::Rust, &[2, 3], false);
9999
assert_eq!(colors.len(), 2);
100100
assert_eq!(colors, vec![num_to_color(&2), num_to_color(&3)]);
101101
}
@@ -104,7 +104,7 @@ mod test {
104104
fn get_ascii_colors_fill_custom_colors_with_language_colors() {
105105
// When custom ascii colors are not enough for the given language,
106106
// language colors should be used as default
107-
let colors = get_ascii_colors(&None, &Language::Go, &[0], false);
107+
let colors = get_ascii_colors(None, &Language::Go, &[0], false);
108108
assert_eq!(colors.len(), 3);
109109
assert_eq!(
110110
colors,

0 commit comments

Comments
 (0)