pub trait LocationLike: Sized {
Show 17 methods // Required methods fn row(&self) -> Row; fn column(&self) -> Column; // Provided methods 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) -> Ordered<Self, Major> { ... } fn row_ordered(self) -> RowOrdered<Self> { ... } fn column_ordered(self) -> ColumnOrdered<Self> { ... } fn span_over<C: VecComponent>( self, distance: C ) -> LocationRange<<C::Point as Component>::Converse> { ... } fn range_to<C: Component>(self, end: C) -> LocationRange<C::Converse> { ... }
}
Expand description

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

Required Methods§

source

fn row(&self) -> Row

Get the row of this location.

source

fn column(&self) -> Column

Get the column of this location.

Provided Methods§

source

fn as_location(&self) -> Location

Convert this object into a Location struct.

source

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.

source

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

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

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

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

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

Return the location that is distance away from this one.

source

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

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

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

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.

source

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

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

fn span_over<C: VecComponent>( self, distance: C ) -> LocationRange<<C::Point as Component>::Converse>

Create a range, starting at this location, with the given length

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

let location = L(1, 2);
let range = location.span_over(Rows(3));

assert_eq!(range, LocationRange::bounded(Column(2), Row(1), Row(4)));
source

fn range_to<C: Component>(self, end: C) -> LocationRange<C::Converse>

Create a range, starting at this component, ending at the given component

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

let location = L(1, 2);
let range = location.range_to(Column(6));

assert_eq!(range, LocationRange::bounded(Row(1), Column(2), Column(6)));

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl LocationLike for (isize, isize)

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

source§

fn row(&self) -> Row

source§

fn column(&self) -> Column

source§

fn as_location(&self) -> Location

source§

impl LocationLike for (Column, Row)

source§

fn column(&self) -> Column

source§

fn row(&self) -> Row

source§

fn as_location(&self) -> Location

source§

impl LocationLike for (Row, Column)

source§

fn row(&self) -> Row

source§

fn column(&self) -> Column

source§

fn as_location(&self) -> Location

source§

impl<T: LocationLike> LocationLike for &T

source§

fn row(&self) -> Row

source§

fn column(&self) -> Column

source§

fn as_location(&self) -> Location

Implementors§