Skip to content

Commit

Permalink
style: do not dereference self to perform pattern-matching
Browse files Browse the repository at this point in the history
Dereferencing `self` as `*self` in order to perform patten-matching
using `ref` is unnecessary and will be done automatically by the
compiler (match ergonomics, introduced in Rust 1.26).
  • Loading branch information
samueltardieu committed Jan 14, 2023
1 parent c6d9024 commit bdaebf3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
12 changes: 6 additions & 6 deletions lib/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,25 +230,25 @@ pub enum TreeValue {
impl ContentHash for TreeValue {
fn hash(&self, state: &mut impl digest::Update) {
use TreeValue::*;
match *self {
File { ref id, executable } => {
match self {
File { id, executable } => {
state.update(&0u32.to_le_bytes());
id.hash(state);
executable.hash(state);
}
Symlink(ref id) => {
Symlink(id) => {
state.update(&1u32.to_le_bytes());
id.hash(state);
}
Tree(ref id) => {
Tree(id) => {
state.update(&2u32.to_le_bytes());
id.hash(state);
}
GitSubmodule(ref id) => {
GitSubmodule(id) => {
state.update(&3u32.to_le_bytes());
id.hash(state);
}
Conflict(ref id) => {
Conflict(id) => {
state.update(&4u32.to_le_bytes());
id.hash(state);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/content_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ impl ContentHash for String {

impl<T: ContentHash> ContentHash for Option<T> {
fn hash(&self, state: &mut impl digest::Update) {
match *self {
match self {
None => state.update(&[0]),
Some(ref x) => {
Some(x) => {
state.update(&[1]);
x.hash(state)
}
Expand Down
9 changes: 3 additions & 6 deletions lib/src/op_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,12 @@ pub enum RefTarget {
impl ContentHash for RefTarget {
fn hash(&self, state: &mut impl digest::Update) {
use RefTarget::*;
match *self {
Normal(ref id) => {
match self {
Normal(id) => {
state.update(&0u32.to_le_bytes());
id.hash(state);
}
Conflict {
ref removes,
ref adds,
} => {
Conflict { removes, adds } => {
state.update(&1u32.to_le_bytes());
removes.hash(state);
adds.hash(state);
Expand Down
6 changes: 3 additions & 3 deletions lib/src/simple_op_store_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ impl TSerializable for RefTarget {
fn write_to_out_protocol(&self, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
let struct_ident = TStructIdentifier::new("RefTarget");
o_prot.write_struct_begin(&struct_ident)?;
match *self {
RefTarget::CommitId(ref f) => {
match self {
RefTarget::CommitId(f) => {
o_prot.write_field_begin(&TFieldIdentifier::new("commit_id", TType::String, 1))?;
o_prot.write_bytes(f)?;
o_prot.write_field_end()?;
},
RefTarget::Conflict(ref f) => {
RefTarget::Conflict(f) => {
o_prot.write_field_begin(&TFieldIdentifier::new("conflict", TType::Struct, 2))?;
f.write_to_out_protocol(o_prot)?;
o_prot.write_field_end()?;
Expand Down

0 comments on commit bdaebf3

Please sign in to comment.