Skip to content

Commit

Permalink
Added Rust GitHub workflows.
Browse files Browse the repository at this point in the history
  • Loading branch information
vsbuffalo committed Feb 15, 2024
1 parent 184a320 commit feaa2ad
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Rust

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "granges2"
name = "granges"
version = "0.1.0"
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (2024) Vince Buffalo
#![crate_name = "granges2"]
#![crate_name = "granges"]
#![doc(html_root_url = "https://docs.rs/granges/")]

pub mod error;
Expand Down
10 changes: 9 additions & 1 deletion src/ranges/coitrees.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use coitrees::{BasicCOITree, GenericInterval, Interval, IntervalNode, IntervalTree};

use crate::{error::GRangesError, iterators::RangesIterable, traits::RangeContainer, Position};
use crate::{error::GRangesError, iterators::{RangesIterable, RangesIntoIterable}, traits::RangeContainer, Position};

use super::{validate_range, vec::VecRanges, RangeEmpty, RangeIndexed};

Expand Down Expand Up @@ -121,6 +121,14 @@ impl From<Interval<&usize>> for RangeIndexed {
}
}


///
/// # Developer Notes
///
/// Internally, the [`coitrees`] iterator is over their interval type.
/// Their iterator does not consume, but we need an owned (or copyable,
/// as is case here) type to map out. Thus, we need this odd variant of
/// an iterator that doesn't return references and does not consume.
impl RangesIterable<RangeIndexed> for COITrees<usize> {
fn iter_ranges(&self) -> Box<dyn Iterator<Item = RangeIndexed> + '_> {
let iter = self.ranges.iter();
Expand Down
11 changes: 10 additions & 1 deletion src/ranges/vec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{error::GRangesError, traits::RangeContainer, Position};

use crate::iterators::{RangesIterable, RangesIntoIterable};
use super::{validate_range, RangeEmpty, RangeIndexed};

pub type VecRangesIndexed = VecRanges<RangeIndexed>;
pub type VecRangesEmpty = VecRanges<RangeEmpty>;

Expand Down Expand Up @@ -45,3 +46,11 @@ impl<R: Clone> RangeContainer for VecRanges<R> {
self.ranges.len()
}
}


impl RangesIntoIterable<RangeIndexed> for VecRanges<RangeIndexed> {
fn into_iter_ranges(self) -> Box<dyn Iterator<Item = RangeIndexed>> {
let iter = self.ranges.into_iter();
Box::new(iter)
}
}

0 comments on commit feaa2ad

Please sign in to comment.