Crates.io | rect-lib |
lib.rs | rect-lib |
version | 0.1.1 |
source | src |
created_at | 2024-04-22 19:10:16.407457 |
updated_at | 2024-04-22 19:22:38.590901 |
description | A simple library for working with anything vaguely rectangular |
homepage | https://github.com/5-pebbles/rect-lib |
repository | https://github.com/5-pebbles/rect-lib |
max_upload_size | |
id | 1216435 |
size | 134,811 |
A simple library for working with anything vaguely rectangular in rust.
Rectangle trait: a trait implementing all rectangle operations; see documentation.
BasicRectangle: a simple implementation of the Rectangle
trait.
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,
}
}
}
This project is licensed under GPL-v3.