Skip to content

Use Self where possible #1166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<'repo> Blame<'repo> {
}

impl<'blame> BlameHunk<'blame> {
unsafe fn from_raw_const(raw: *const raw::git_blame_hunk) -> BlameHunk<'blame> {
unsafe fn from_raw_const(raw: *const raw::git_blame_hunk) -> Self {
BlameHunk {
raw: raw as *mut raw::git_blame_hunk,
_marker: marker::PhantomData,
Expand Down Expand Up @@ -172,7 +172,7 @@ impl Default for BlameOptions {

impl BlameOptions {
/// Initialize options
pub fn new() -> BlameOptions {
pub fn new() -> Self {
unsafe {
let mut raw: raw::git_blame_options = mem::zeroed();
assert_eq!(
Expand All @@ -184,7 +184,7 @@ impl BlameOptions {
}
}

fn flag(&mut self, opt: u32, val: bool) -> &mut BlameOptions {
fn flag(&mut self, opt: u32, val: bool) -> &mut Self {
if val {
self.raw.flags |= opt;
} else {
Expand All @@ -194,69 +194,69 @@ impl BlameOptions {
}

/// Track lines that have moved within a file.
pub fn track_copies_same_file(&mut self, opt: bool) -> &mut BlameOptions {
pub fn track_copies_same_file(&mut self, opt: bool) -> &mut Self {
self.flag(raw::GIT_BLAME_TRACK_COPIES_SAME_FILE, opt)
}

/// Track lines that have moved across files in the same commit.
pub fn track_copies_same_commit_moves(&mut self, opt: bool) -> &mut BlameOptions {
pub fn track_copies_same_commit_moves(&mut self, opt: bool) -> &mut Self {
self.flag(raw::GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES, opt)
}

/// Track lines that have been copied from another file that exists
/// in the same commit.
pub fn track_copies_same_commit_copies(&mut self, opt: bool) -> &mut BlameOptions {
pub fn track_copies_same_commit_copies(&mut self, opt: bool) -> &mut Self {
self.flag(raw::GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES, opt)
}

/// Track lines that have been copied from another file that exists
/// in any commit.
pub fn track_copies_any_commit_copies(&mut self, opt: bool) -> &mut BlameOptions {
pub fn track_copies_any_commit_copies(&mut self, opt: bool) -> &mut Self {
self.flag(raw::GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES, opt)
}

/// Restrict the search of commits to those reachable following only
/// the first parents.
pub fn first_parent(&mut self, opt: bool) -> &mut BlameOptions {
pub fn first_parent(&mut self, opt: bool) -> &mut Self {
self.flag(raw::GIT_BLAME_FIRST_PARENT, opt)
}

/// Use mailmap file to map author and committer names and email addresses
/// to canonical real names and email addresses. The mailmap will be read
/// from the working directory, or HEAD in a bare repository.
pub fn use_mailmap(&mut self, opt: bool) -> &mut BlameOptions {
pub fn use_mailmap(&mut self, opt: bool) -> &mut Self {
self.flag(raw::GIT_BLAME_USE_MAILMAP, opt)
}

/// Ignore whitespace differences.
pub fn ignore_whitespace(&mut self, opt: bool) -> &mut BlameOptions {
pub fn ignore_whitespace(&mut self, opt: bool) -> &mut Self {
self.flag(raw::GIT_BLAME_IGNORE_WHITESPACE, opt)
}

/// Setter for the id of the newest commit to consider.
pub fn newest_commit(&mut self, id: Oid) -> &mut BlameOptions {
pub fn newest_commit(&mut self, id: Oid) -> &mut Self {
unsafe {
self.raw.newest_commit = *id.raw();
}
self
}

/// Setter for the id of the oldest commit to consider.
pub fn oldest_commit(&mut self, id: Oid) -> &mut BlameOptions {
pub fn oldest_commit(&mut self, id: Oid) -> &mut Self {
unsafe {
self.raw.oldest_commit = *id.raw();
}
self
}

/// The first line in the file to blame.
pub fn min_line(&mut self, lineno: usize) -> &mut BlameOptions {
pub fn min_line(&mut self, lineno: usize) -> &mut Self {
self.raw.min_line = lineno;
self
}

/// The last line in the file to blame.
pub fn max_line(&mut self, lineno: usize) -> &mut BlameOptions {
pub fn max_line(&mut self, lineno: usize) -> &mut Self {
self.raw.max_line = lineno;
self
}
Expand All @@ -265,7 +265,7 @@ impl BlameOptions {
impl<'repo> Binding for Blame<'repo> {
type Raw = *mut raw::git_blame;

unsafe fn from_raw(raw: *mut raw::git_blame) -> Blame<'repo> {
unsafe fn from_raw(raw: *mut raw::git_blame) -> Self {
Blame {
raw,
_marker: marker::PhantomData,
Expand All @@ -286,7 +286,7 @@ impl<'repo> Drop for Blame<'repo> {
impl<'blame> Binding for BlameHunk<'blame> {
type Raw = *mut raw::git_blame_hunk;

unsafe fn from_raw(raw: *mut raw::git_blame_hunk) -> BlameHunk<'blame> {
unsafe fn from_raw(raw: *mut raw::git_blame_hunk) -> Self {
BlameHunk {
raw,
_marker: marker::PhantomData,
Expand All @@ -301,8 +301,8 @@ impl<'blame> Binding for BlameHunk<'blame> {
impl Binding for BlameOptions {
type Raw = *mut raw::git_blame_options;

unsafe fn from_raw(opts: *mut raw::git_blame_options) -> BlameOptions {
BlameOptions { raw: *opts }
unsafe fn from_raw(opts: *mut raw::git_blame_options) -> Self {
Self { raw: *opts }
}

fn raw(&self) -> *mut raw::git_blame_options {
Expand Down
4 changes: 2 additions & 2 deletions src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'repo> Blob<'repo> {
impl<'repo> Binding for Blob<'repo> {
type Raw = *mut raw::git_blob;

unsafe fn from_raw(raw: *mut raw::git_blob) -> Blob<'repo> {
unsafe fn from_raw(raw: *mut raw::git_blob) -> Self {
Blob {
raw,
_marker: marker::PhantomData,
Expand Down Expand Up @@ -108,7 +108,7 @@ impl<'repo> BlobWriter<'repo> {
impl<'repo> Binding for BlobWriter<'repo> {
type Raw = *mut raw::git_writestream;

unsafe fn from_raw(raw: *mut raw::git_writestream) -> BlobWriter<'repo> {
unsafe fn from_raw(raw: *mut raw::git_writestream) -> Self {
BlobWriter {
raw,
need_cleanup: true,
Expand Down
6 changes: 3 additions & 3 deletions src/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'repo> Branch<'repo> {
}

/// Move/rename an existing local branch reference.
pub fn rename(&mut self, new_branch_name: &str, force: bool) -> Result<Branch<'repo>, Error> {
pub fn rename(&mut self, new_branch_name: &str, force: bool) -> Result<Self, Error> {
let mut ret = ptr::null_mut();
let new_branch_name = CString::new(new_branch_name)?;
unsafe {
Expand Down Expand Up @@ -100,7 +100,7 @@ impl<'repo> Branch<'repo> {

/// Return the reference supporting the remote tracking branch, given a
/// local branch reference.
pub fn upstream(&self) -> Result<Branch<'repo>, Error> {
pub fn upstream(&self) -> Result<Self, Error> {
let mut ret = ptr::null_mut();
unsafe {
try_call!(raw::git_branch_upstream(&mut ret, &*self.get().raw()));
Expand Down Expand Up @@ -129,7 +129,7 @@ impl<'repo> Branches<'repo> {
///
/// This function is unsafe as it is not guaranteed that `raw` is a valid
/// pointer.
pub unsafe fn from_raw(raw: *mut raw::git_branch_iterator) -> Branches<'repo> {
pub unsafe fn from_raw(raw: *mut raw::git_branch_iterator) -> Self {
Branches {
raw,
_marker: marker::PhantomData,
Expand Down
6 changes: 3 additions & 3 deletions src/buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Default for Buf {

impl Buf {
/// Creates a new empty buffer.
pub fn new() -> Buf {
pub fn new() -> Self {
crate::init();
unsafe {
Binding::from_raw(&mut raw::git_buf {
Expand Down Expand Up @@ -56,8 +56,8 @@ impl DerefMut for Buf {

impl Binding for Buf {
type Raw = *mut raw::git_buf;
unsafe fn from_raw(raw: *mut raw::git_buf) -> Buf {
Buf { raw: *raw }
unsafe fn from_raw(raw: *mut raw::git_buf) -> Self {
Self { raw: *raw }
}
fn raw(&self) -> *mut raw::git_buf {
&self.raw as *const _ as *mut _
Expand Down
Loading