[][src]Trait gridly::prelude::LocationLike

pub trait LocationLike: Sized {
    fn row(&self) -> Row;
fn column(&self) -> Column; #[must_use] fn as_location(&self) -> Location { ... }
#[must_use] fn get_component<T: Component>(&self) -> T { ... }
#[must_use] fn above(&self, distance: impl Into<Rows>) -> Location { ... }
#[must_use] fn below(&self, distance: impl Into<Rows>) -> Location { ... }
#[must_use] fn left(&self, distance: impl Into<Columns>) -> Location { ... }
#[must_use] fn right(&self, distance: impl Into<Columns>) -> Location { ... }
#[must_use] fn add(&self, distance: impl VectorLike) -> Location { ... }
#[must_use] fn relative(&self, direction: Direction, distance: isize) -> Location { ... }
#[must_use] fn step(&self, direction: Direction) -> Location { ... }
#[must_use] fn transpose(&self) -> Location { ... }
#[must_use] fn order_by<Major: Component>(self) -> Ordered<Self, Major> { ... }
#[must_use] fn row_ordered(self) -> RowOrdered<Self> { ... }
#[must_use] 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

Get the row of this location.

fn column(&self) -> Column

Get the column of this location.

Loading content...

Provided methods

#[must_use] fn as_location(&self) -> Location

Convert this object into a Location struct.

#[must_use] 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.

#[must_use] 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));

#[must_use] 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));

#[must_use] 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));

#[must_use] 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));

#[must_use] fn add(&self, distance: impl VectorLike) -> Location

Return the location that is distance away from this one.

#[must_use] 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));

#[must_use] 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));

#[must_use] 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));

#[must_use] fn order_by<Major: Component>(self) -> Ordered<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.

#[must_use] 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 column.

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);

#[must_use] fn column_ordered(self) -> ColumnOrdered<Self>

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

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]

A pair of isize values acts as a (Row, Column) pair.

Loading content...

Implementors

impl LocationLike for Location[src]

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

Loading content...