Skip to main content

Along

Trait Along 

Source
pub trait Along {
    type Unit;

    // Required methods
    fn along(&self, axis: Axis) -> Self::Unit;
    fn apply_along(
        &self,
        axis: Axis,
        f: impl FnOnce(Self::Unit) -> Self::Unit,
    ) -> Self;
}
Expand description

Reads and updates the value along one Axis.

Point and Size implement this trait. The horizontal axis is x for a point and width for a size. The vertical axis is y and height.

§Examples

use gpui::{Along, Axis, point, px};

let mut position = point(px(10.), px(20.));
position = position.apply_along(Axis::Vertical, |y| y + px(5.));
assert_eq!(position.along(Axis::Vertical), px(25.));

Required Associated Types§

Source

type Unit

The type of the value along each axis.

Required Methods§

Source

fn along(&self, axis: Axis) -> Self::Unit

Returns the value along axis.

Source

fn apply_along( &self, axis: Axis, f: impl FnOnce(Self::Unit) -> Self::Unit, ) -> Self

Returns a copy with f applied to the value along axis. The other axis is unchanged.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: Clone + Debug + Default + PartialEq> Along for Point<T>

Source§

type Unit = T

Source§

impl<T> Along for Size<T>
where T: Clone + Debug + Default + PartialEq,

Source§

type Unit = T