pub struct Rect {
    pub top_left: Point,
    pub top_right: Point,
    pub bottom_right: Point,
    pub bottom_left: Point,
    pub size: Size,
}
Expand description

A rectangle, described by its four corners and a size.

Fields

top_left: Point

The top-left corner.

top_right: Point

The top-right corner.

bottom_right: Point

The bottom-right corner.

bottom_left: Point

The bottom-left corner.

size: Size

The Rectangle’s size.

Implementations

Construct a Rect from its top-left corner and its size.

Examples
let rect = Rect::from_size(Point::new(10, 20), Size::new(30, 40));
assert_eq!(rect.top_left, Point::new(10, 20));
assert_eq!(rect.top_right, Point::new(40, 20));
assert_eq!(rect.bottom_left, Point::new(10, 60));
assert_eq!(rect.bottom_right, Point::new(40, 60));
assert_eq!(rect.size, Size::new(30, 40));

Construct a Rect from its top-left and bottom-right corners.

Examples
let rect = Rect::from_points(Point::new(10, 20), Point::new(30, 40));
assert_eq!(rect.top_left, Point::new(10, 20));
assert_eq!(rect.top_right, Point::new(30, 20));
assert_eq!(rect.bottom_left, Point::new(10, 40));
assert_eq!(rect.bottom_right, Point::new(30, 40));
assert_eq!(rect.size, Size::new(20, 20));

Construct a Rect from its top-left corner and its size, values unwrapped.

Examples
assert_eq!(Rect::from_values(10, 20, 30, 40), Rect::from_size(Point::new(10, 20), Size::new(30, 40)));

Construct a Rect from its top-left and bottom-right corners, values unwrapped.

Examples
assert_eq!(Rect::from_point_values(10, 20, 30, 40), Rect::from_points(Point::new(10, 20), Point::new(30, 40)));

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.