gamo

Crates.iogamo
lib.rsgamo
version0.3.0
sourcesrc
created_at2023-10-20 13:49:15.054398
updated_at2024-01-11 23:50:18.502593
descriptionA Range like struct for user defined types
homepage
repositoryhttps://github.com/lucidfrontier45/gamo
max_upload_size
id1009010
size6,937
杜世橋 Du Shiqiao (lucidfrontier45)

documentation

https://docs.rs/gamo

README

Gamo

Create a Range like struct of user define types for easy for loop. Gamo means range in Esperanto.

What is it?

Currently Rust does not have a stable API to create Range<T> of user defined type T. This crate provides a Range like struct Gamo that can be easily used with for-loops.

Usage

[dependencies]
gamo = "0.2.0"

The type T used in Gamo<T> must implement TryToNext trait.

Example

use gamo::{Gamo, TryToNext};

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
struct TimeSlot(usize);

impl TryToNext for TimeSlot {
    fn try_to_next(&self) -> Option<Self> {
        Some(Self(self.0 + 1))
    }
}

fn main() {
    for t in Gamo::new(TimeSlot(0), TimeSlot(5)) {
        println!("{:?}", t);
    }
}
Commit count: 2

cargo fmt