[][src]Trait gridly::location::LocationLike

pub trait LocationLike: Sized {
    fn row(&self) -> Row;
fn column(&self) -> Column; fn as_location(&self) -> Location { ... }
fn get_component<T: Component>(&self) -> T { ... }
fn above(&self, distance: impl Into<Rows>) -> Location { ... }
fn below(&self, distance: impl Into<Rows>) -> Location { ... }
fn left(&self, distance: impl Into<Columns>) -> Location { ... }
fn right(&self, distance: impl Into<Columns>) -> Location { ... }
fn add(&self, distance: impl VectorLike) -> Location { ... }
fn relative(&self, direction: Direction, distance: isize) -> Location { ... }
fn step(&self, direction: Direction) -> Location { ... }
fn transpose(&self) -> Location { ... }
fn order_by<Major: Component>(self) -> OrderedLocation<Self, Major> { ... }
fn row_ordered(self) -> RowOrdered<Self> { ... }
fn column_ordered(self) -> ColumnOrdered<Self> { ... } }

This trait covers structs that act like a Location, such as tuples. See the Location documentation for more details.

Required methods

fn row(&self) -> Row

fn column(&self) -> Column

Loading content...

Provided methods

fn as_location(&self) -> Location

fn get_component<T: Component>(&self) -> T

Get either the row or column of a location. This method is useful in code that is generic over the Row or Column.

fn above(&self, distance: impl Into<Rows>) -> Location

Return the location that is distance rows above this one

use gridly::prelude::*;
use gridly::shorthand::*;

assert_eq!(L(3, 4).above(2), L(1, 4));

fn below(&self, distance: impl Into<Rows>) -> Location

Return the location that is distance rows below this one

use gridly::prelude::*;
use gridly::shorthand::*;

assert_eq!(L(3, 4).below(2), L(5, 4));

fn left(&self, distance: impl Into<Columns>) -> Location

Return the location that is distance columns to the left of this one

use gridly::prelude::*;
use gridly::shorthand::*;

assert_eq!(L(3, 4).left(2), L(3, 2));

fn right(&self, distance: impl Into<Columns>) -> Location

Return the location that is distance columns to the right of this one

use gridly::prelude::*;
use gridly::shorthand::*;

assert_eq!(L(3, 4).right(2), L(3, 6));

fn add(&self, distance: impl VectorLike) -> Location

fn relative(&self, direction: Direction, distance: isize) -> Location

Return the location that is distance away in the given direction

use gridly::prelude::*;
use gridly::shorthand::*;

assert_eq!(Location::zero().relative(Up, 4), L(-4, 0));
assert_eq!(Location::zero().relative(Down, 5), L(5, 0));
assert_eq!(Location::zero().relative(Left, 3), L(0, -3));
assert_eq!(Location::zero().relative(Right, 1), L(0, 1));

fn step(&self, direction: Direction) -> Location

Return the location that is 1 away in the given direction

use gridly::prelude::*;
use gridly::shorthand::*;

let base = Location::new(2, 4);
assert_eq!(base.step(Up), L(1, 4));
assert_eq!(base.step(Down), L(3, 4));
assert_eq!(base.step(Left), L(2, 3));
assert_eq!(base.step(Right), L(2, 5));

fn transpose(&self) -> Location

Swap the row and colimn of this Location

Example:

use gridly::prelude::*;
use gridly::shorthand::*;

assert_eq!(L(5, 8).transpose(), L(8, 5));

fn order_by<Major: Component>(self) -> OrderedLocation<Self, Major>

Generically get strictly ordered version of this Location. The Major is the ordering; for example, order_by::<Row> will create a row-ordered Location. See [row_ordered] or [column_ordered] for an example.

fn row_ordered(self) -> RowOrdered<Self>

Get a strictly row-ordered version of this Location; that is, a location which is ordered by comparing the row, then the columns.

Example:

use gridly::prelude::*;
use gridly::shorthand::*;

let l0 = L(0, 0).row_ordered();
let l1 = L(0, 1).row_ordered();
let l2 = L(1, 0).row_ordered();
let l3 = L(1, 1).row_ordered();

assert!(l0 < l1 && l0 < l2 && l0 < l3);
assert!(l1 < l2 && l1 < l3);
assert!(l2 < l3);

fn column_ordered(self) -> ColumnOrdered<Self>

which is ordered by comparing the row, then the columns.

Example:


use gridly::prelude::*;
use gridly::shorthand::*;

let l0 = L(0, 0).column_ordered();
let l1 = L(1, 0).column_ordered();
let l2 = L(0, 1).column_ordered();
let l3 = L(1, 1).column_ordered();

assert!(l0 < l1 && l0 < l2 && l0 < l3);
assert!(l1 < l2 && l1 < l3);
assert!(l2 < l3);
Loading content...

Implementations on Foreign Types

impl LocationLike for (Row, Column)[src]

impl LocationLike for (Column, Row)[src]

impl<'_, T: LocationLike> LocationLike for &'_ T[src]

impl LocationLike for (isize, isize)[src]

Loading content...

Implementors

impl LocationLike for Location[src]

impl<L: LocationLike, M: Component> LocationLike for OrderedLocation<L, M>[src]

Loading content...