pub trait Component:
Sized
+ From<isize>
+ Copy
+ Ord
+ Eq
+ Debug
+ Add
+ AddAssign
+ Sub
+ SubAssign
+ Neg
+ Default
+ PartialEq<isize>
+ PartialOrd<isize>
+ VectorLike
+ Sum {
type Converse: Component<Converse = Self>;
type Point: LocComponent<Distance = Self>;
// Required methods
fn from_vector(vector: impl VectorLike) -> Self;
fn combine(self, converse: Self::Converse) -> Vector;
fn value(self) -> isize;
fn transpose(self) -> Self::Converse;
}
Expand description
A Rows
or Columns
component of a Vector
This trait comprises a component of a Vector
, which may be either
Rows
or Columns
. It represents a distance in a single direction,
either vertical (Rows
) or horizontal (Columns
).
In practice, most code will call methods directly on Rows
or Columns
values. However, a lot of gridly functionality is agnostic towards
rows and columns (for instance, a view over a row in a grid is functionally
the same as a view over a column), so the Component
trait allows such
functionality to be written generically.
The key methods for Component
that allow it to work in generic contexts
are from_vector
, which gets a component from a Vector
, and combine
,
which combines a Rows
or Columns
with its converse (a Columns
or a Row
s) to create a new Vector
.
Required Associated Types§
Required Methods§
Sourcefn from_vector(vector: impl VectorLike) -> Self
fn from_vector(vector: impl VectorLike) -> Self
Sourcefn combine(self, converse: Self::Converse) -> Vector
fn combine(self, converse: Self::Converse) -> Vector
Create a vector from a Row and Column
§Example:
use gridly::vector::*;
let columns = Columns(10);
let rows = Rows(2);
assert_eq!(columns.combine(rows), Vector::new(2, 10));
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.