rect-lib 0.1.1

A simple library for working with anything vaguely rectangular
Documentation
  • Coverage
  • 94.74%
    18 out of 19 items documented16 out of 16 items with examples
  • Size
  • Source code size: 136.43 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 786.00 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Homepage
  • 5-pebbles/rect-lib
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • 5-pebbles

rect-lib 📐

A simple library for working with anything vaguely rectangular in rust.

Features 📦

  • Rectangle trait: a trait implementing all rectangle operations; see documentation.

  • BasicRectangle: a simple implementation of the Rectangle trait.

Usage 🚀

Add the crate to your Cargo.toml:

[dependencies]
rect-lib = "0.1.1"

or use cargo add:

cargo add rect-lib

Then, you can use the Rectangle trait in your code:

use rect_lib::Rectangle;

#[derive(Clone, Copy)]
pub struct BasicRectangle {
    x: i32,
    y: i32,
    width: i32,
    height: i32,
}

impl Rectangle for BasicRectangle {
    type Unit = i32;

    fn left(&self) -> i32 {
        self.x
    }

    fn right(&self) -> i32 {
        self.x + self.width - 1
    }

    fn top(&self) -> i32 {
        self.y
    }

    fn bottom(&self) -> i32 {
        self.y - self.height + 1
    }

    fn new_from_sides(left: i32, right: i32, top: i32, bottom: i32) -> Self {
        Self {
            x: left,
            y: top,
            width: right - left + 1,
            height: top - bottom + 1,
        }
    }
}

License 📜

This project is licensed under GPL-v3.