Skip to content

Commit 6eb361b

Browse files
fixed clippy warnings (#268)
1 parent 1875793 commit 6eb361b

File tree

4 files changed

+33
-29
lines changed

4 files changed

+33
-29
lines changed

src/bam/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use std::convert::TryInto;
3636
/// # Safety
3737
///
3838
/// Implementation for `Read::set_threads` and `Writer::set_threads`.
39-
pub unsafe fn set_threads(htsfile: *mut htslib::htsFile, n_threads: usize) -> Result<()> {
39+
unsafe fn set_threads(htsfile: *mut htslib::htsFile, n_threads: usize) -> Result<()> {
4040
assert!(n_threads != 0, "n_threads must be > 0");
4141

4242
if htslib::hts_set_threads(htsfile, n_threads as i32) != 0 {
@@ -46,7 +46,7 @@ pub unsafe fn set_threads(htsfile: *mut htslib::htsFile, n_threads: usize) -> Re
4646
}
4747
}
4848

49-
pub unsafe fn set_thread_pool(htsfile: *mut htslib::htsFile, tpool: &ThreadPool) -> Result<()> {
49+
unsafe fn set_thread_pool(htsfile: *mut htslib::htsFile, tpool: &ThreadPool) -> Result<()> {
5050
let mut b = tpool.handle.borrow_mut();
5151

5252
if htslib::hts_set_thread_pool(htsfile, &mut b.inner as *mut _) != 0 {

src/bcf/buffer.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// This file may not be copied, modified, or distributed
44
// except according to those terms.
55

6+
use std::cmp::Ordering;
67
use std::collections::{vec_deque, VecDeque};
78
use std::mem;
89

@@ -131,26 +132,30 @@ impl RecordBuffer {
131132
}
132133
let pos = rec.pos() as u64;
133134
if let Some(rec_rid) = rec.rid() {
134-
if rec_rid == rid {
135-
if pos >= end {
136-
// Record is beyond our window. Store it anyways but stop.
137-
self.overflow = Some(rec);
135+
match rec_rid.cmp(&rid) {
136+
Ordering::Equal => {
137+
if pos >= end {
138+
// Record is beyond our window. Store it anyways but stop.
139+
self.overflow = Some(rec);
140+
break;
141+
} else if pos >= start {
142+
// Record is within our window.
143+
self.ringbuffer.push_back(rec);
144+
added += 1;
145+
} else {
146+
// Record is upstream of our window, ignore it
147+
continue;
148+
}
149+
}
150+
Ordering::Greater => {
151+
// record comes from next rid. Store it in second buffer but stop filling.
152+
self.ringbuffer2.push_back(rec);
138153
break;
139-
} else if pos >= start {
140-
// Record is within our window.
141-
self.ringbuffer.push_back(rec);
142-
added += 1;
143-
} else {
144-
// Record is upstream of our window, ignore it
154+
}
155+
_ => {
156+
// Record comes from previous rid. Ignore it.
145157
continue;
146158
}
147-
} else if rec_rid > rid {
148-
// record comes from next rid. Store it in second buffer but stop filling.
149-
self.ringbuffer2.push_back(rec);
150-
break;
151-
} else {
152-
// Record comes from previous rid. Ignore it.
153-
continue;
154159
}
155160
} else {
156161
// skip records without proper rid

src/lib.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@
2525
//! ```
2626
//! use rust_htslib::{bam, bam::Read};
2727
//!
28-
//! fn main() {
29-
//! let bam = bam::Reader::from_path(&"test/test.bam").unwrap();
30-
//! let header = bam::Header::from_template(bam.header());
31-
//!
32-
//! // print header records to the terminal, akin to samtool
33-
//! for (key, records) in header.to_hashmap() {
34-
//! for record in records {
35-
//! println!("@{}\tSN:{}\tLN:{}", key, record["SN"], record["LN"]);
36-
//! }
28+
//!
29+
//! let bam = bam::Reader::from_path(&"test/test.bam").unwrap();
30+
//! let header = bam::Header::from_template(bam.header());
31+
//!
32+
//! // print header records to the terminal, akin to samtool
33+
//! for (key, records) in header.to_hashmap() {
34+
//! for record in records {
35+
//! println!("@{}\tSN:{}\tLN:{}", key, record["SN"], record["LN"]);
3736
//! }
3837
//! }
3938
//! ```

src/tpool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub struct InnerThreadPool {
4444

4545
impl Drop for InnerThreadPool {
4646
fn drop(&mut self) {
47-
if self.inner.pool != std::ptr::null_mut() {
47+
if !self.inner.pool.is_null() {
4848
unsafe {
4949
htslib::hts_tpool_destroy(self.inner.pool);
5050
}

0 commit comments

Comments
 (0)