Enum Color

Source
pub enum Color {
    Luma(Luma),
    Oklab(Oklab),
    Oklch(Oklch),
    Rgb(Rgb),
    LinearRgb(LinearRgb),
    Cmyk(Cmyk),
    Hsl(Hsl),
    Hsv(Hsv),
}
Expand description

A color in a specific color space.

Typst supports:

§Example

#rect(fill: aqua)

§Predefined colors

Typst defines the following built-in colors:

ColorDefinition
black{luma(0)}
gray{luma(170)}
silver{luma(221)}
white{luma(255)}
navy{rgb("#001f3f")}
blue{rgb("#0074d9")}
aqua{rgb("#7fdbff")}
teal{rgb("#39cccc")}
eastern{rgb("#239dad")}
purple{rgb("#b10dc9")}
fuchsia{rgb("#f012be")}
maroon{rgb("#85144b")}
red{rgb("#ff4136")}
orange{rgb("#ff851b")}
yellow{rgb("#ffdc00")}
olive{rgb("#3d9970")}
green{rgb("#2ecc40")}
lime{rgb("#01ff70")}

The predefined colors and the most important color constructors are available globally and also in the color type’s scope, so you can write either color.red or just red.

#let colors = (
  "black", "gray", "silver", "white",
  "navy", "blue", "aqua", "teal",
  "eastern", "purple", "fuchsia",
  "maroon", "red", "orange", "yellow",
  "olive", "green", "lime",
)

#set text(font: "PT Sans")
#set page(width: auto)
#grid(
  columns: 9,
  gutter: 10pt,
  ..colors.map(name => {
      let col = eval(name)
      let luminance = luma(col).components().first()
      set text(fill: white) if luminance < 50%
      set square(stroke: black) if col == white
      set align(center + horizon)
      square(size: 50pt,  fill: col, name)
  })
)

§Predefined color maps

Typst also includes a number of preset color maps that can be used for gradients. These are simply arrays of colors defined in the module color.map.

#circle(fill: gradient.linear(..color.map.crest))
MapDetails
turboA perceptually uniform rainbow-like color map. Read this blog post for more details.
cividisA blue to gray to yellow color map. See this blog post for more details.
rainbowCycles through the full color spectrum. This color map is best used by setting the interpolation color space to HSL. The rainbow gradient is not suitable for data visualization because it is not perceptually uniform, so the differences between values become unclear to your readers. It should only be used for decorative purposes.
spectralRed to yellow to blue color map.
viridisA purple to teal to yellow color map.
infernoA black to red to yellow color map.
magmaA black to purple to yellow color map.
plasmaA purple to pink to yellow color map.
rocketA black to red to white color map.
makoA black to teal to yellow color map.
vlagA light blue to white to red color map.
icefireA light teal to black to yellow color map.
flareA orange to purple color map that is perceptually uniform.
crestA blue to white to red color map.

Some popular presets are not included because they are not available under a free licence. Others, like Jet, are not included because they are not color blind friendly. Feel free to use or create a package with other presets that are useful to you!

#set page(width: auto, height: auto)
#set text(font: "PT Sans", size: 8pt)

#let maps = (
  "turbo", "cividis", "rainbow", "spectral",
  "viridis", "inferno", "magma", "plasma",
  "rocket", "mako", "vlag", "icefire",
  "flare", "crest",
)

#stack(dir: ltr, spacing: 3pt, ..maps.map((name) => {
  let map = eval("color.map." + name)
  stack(
    dir: ttb,
    block(
      width: 15pt,
      height: 100pt,
      fill: gradient.linear(..map, angle: 90deg),
    ),
    block(
      width: 15pt,
      height: 32pt,
      move(dy: 8pt, rotate(90deg, name)),
    ),
  )
}))

Variants§

§

Luma(Luma)

A 32-bit luma color.

§

Oklab(Oklab)

A 32-bit L*a*b* color in the Oklab color space.

§

Oklch(Oklch)

A 32-bit LCh color in the Oklab color space.

§

Rgb(Rgb)

A 32-bit RGB color.

§

LinearRgb(LinearRgb)

A 32-bit linear RGB color.

§

Cmyk(Cmyk)

A 32-bit CMYK color.

§

Hsl(Hsl)

A 32-bit HSL color.

§

Hsv(Hsv)

A 32-bit HSV color.

Implementations§

Source§

impl Color

Source

pub const MAP: fn() -> Module = {<{closure@src/visualize/color.rs:215:37: 215:39} as std::ops::FnOnce<()>>::call_once as fn() -> foundations::module::Module}

The module of preset color maps.

Source

pub const BLACK: Self

Source

pub const GRAY: Self

Source

pub const WHITE: Self

Source

pub const SILVER: Self

Source

pub const NAVY: Self

Source

pub const BLUE: Self

Source

pub const AQUA: Self

Source

pub const TEAL: Self

Source

pub const EASTERN: Self

Source

pub const PURPLE: Self

Source

pub const FUCHSIA: Self

Source

pub const MAROON: Self

Source

pub const RED: Self

Source

pub const ORANGE: Self

Source

pub const YELLOW: Self

Source

pub const OLIVE: Self

Source

pub const GREEN: Self

Source

pub const LIME: Self

Source

pub fn luma(args: &mut Args) -> SourceResult<Color>

Create a grayscale color.

A grayscale color is represented internally by a single lightness component.

These components are also available using the components method.

#for x in range(250, step: 50) {
  box(square(fill: luma(x)))
}
Source

pub fn oklab(args: &mut Args) -> SourceResult<Color>

Create an Oklab color.

This color space is well suited for the following use cases:

  • Color manipulation such as saturating while keeping perceived hue
  • Creating grayscale images with uniform perceived lightness
  • Creating smooth and uniform color transition and gradients

A linear Oklab color is represented internally by an array of four components:

  • lightness ([ratio])
  • a ([float] or [ratio]. Ratios are relative to {0.4}; meaning {50%} is equal to {0.2})
  • b ([float] or [ratio]. Ratios are relative to {0.4}; meaning {50%} is equal to {0.2})
  • alpha ([ratio])

These components are also available using the components method.

#square(
  fill: oklab(27%, 20%, -3%, 50%)
)
Source

pub fn oklch(args: &mut Args) -> SourceResult<Color>

Create an Oklch color.

This color space is well suited for the following use cases:

  • Color manipulation involving lightness, chroma, and hue
  • Creating grayscale images with uniform perceived lightness
  • Creating smooth and uniform color transition and gradients

A linear Oklch color is represented internally by an array of four components:

  • lightness ([ratio])
  • chroma ([float] or [ratio]. Ratios are relative to {0.4}; meaning {50%} is equal to {0.2})
  • hue ([angle])
  • alpha ([ratio])

These components are also available using the components method.

#square(
  fill: oklch(40%, 0.2, 160deg, 50%)
)
Source

pub fn linear_rgb(args: &mut Args) -> SourceResult<Color>

Create an RGB(A) color with linear luma.

This color space is similar to sRGB, but with the distinction that the color component are not gamma corrected. This makes it easier to perform color operations such as blending and interpolation. Although, you should prefer to use the oklab function for these.

A linear RGB(A) color is represented internally by an array of four components:

  • red ([ratio])
  • green ([ratio])
  • blue ([ratio])
  • alpha ([ratio])

These components are also available using the components method.

#square(fill: color.linear-rgb(
  30%, 50%, 10%,
))
Source

pub fn rgb(args: &mut Args) -> SourceResult<Color>

Create an RGB(A) color.

The color is specified in the sRGB color space.

An RGB(A) color is represented internally by an array of four components:

  • red ([ratio])
  • green ([ratio])
  • blue ([ratio])
  • alpha ([ratio])

These components are also available using the components method.

#square(fill: rgb("#b1f2eb"))
#square(fill: rgb(87, 127, 230))
#square(fill: rgb(25%, 13%, 65%))
Source

pub fn cmyk(args: &mut Args) -> SourceResult<Color>

Create a CMYK color.

This is useful if you want to target a specific printer. The conversion to RGB for display preview might differ from how your printer reproduces the color.

A CMYK color is represented internally by an array of four components:

  • cyan ([ratio])
  • magenta ([ratio])
  • yellow ([ratio])
  • key ([ratio])

These components are also available using the components method.

Note that CMYK colors are not currently supported when PDF/A output is enabled.

#square(
  fill: cmyk(27%, 0%, 3%, 5%)
)
Source

pub fn hsl(args: &mut Args) -> SourceResult<Color>

Create an HSL color.

This color space is useful for specifying colors by hue, saturation and lightness. It is also useful for color manipulation, such as saturating while keeping perceived hue.

An HSL color is represented internally by an array of four components:

  • hue ([angle])
  • saturation ([ratio])
  • lightness ([ratio])
  • alpha ([ratio])

These components are also available using the components method.

#square(
  fill: color.hsl(30deg, 50%, 60%)
)
Source

pub fn hsv(args: &mut Args) -> SourceResult<Color>

Create an HSV color.

This color space is useful for specifying colors by hue, saturation and value. It is also useful for color manipulation, such as saturating while keeping perceived hue.

An HSV color is represented internally by an array of four components:

  • hue ([angle])
  • saturation ([ratio])
  • value ([ratio])
  • alpha ([ratio])

These components are also available using the components method.

#square(
  fill: color.hsv(30deg, 50%, 60%)
)
Source

pub fn components(self, alpha: bool) -> Array

Extracts the components of this color.

The size and values of this array depends on the color space. You can obtain the color space using space. Below is a table of the color spaces and their components:

Color spaceC1C2C3C4
lumaLightness
oklabLightnessabAlpha
oklchLightnessChromaHueAlpha
linear-rgbRedGreenBlueAlpha
rgbRedGreenBlueAlpha
cmykCyanMagentaYellowKey
hslHueSaturationLightnessAlpha
hsvHueSaturationValueAlpha

For the meaning and type of each individual value, see the documentation of the corresponding color space. The alpha component is optional and only included if the alpha argument is true. The length of the returned array depends on the number of components and whether the alpha component is included.

// note that the alpha component is included by default
#rgb(40%, 60%, 80%).components()
Source

pub fn space(self) -> ColorSpace

Returns the constructor function for this color’s space:

#let color = cmyk(1%, 2%, 3%, 4%)
#(color.space() == cmyk)
Source

pub fn to_hex(self) -> EcoString

Returns the color’s RGB(A) hex representation (such as #ffaa32 or #020304fe). The alpha component (last two digits in #020304fe) is omitted if it is equal to ff (255 / 100%).

Source

pub fn lighten(self, factor: Ratio) -> Color

Lightens a color by a given factor.

Source

pub fn darken(self, factor: Ratio) -> Color

Darkens a color by a given factor.

Source

pub fn saturate(self, span: Span, factor: Ratio) -> SourceResult<Color>

Increases the saturation of a color by a given factor.

Source

pub fn desaturate(self, span: Span, factor: Ratio) -> SourceResult<Color>

Decreases the saturation of a color by a given factor.

Source

pub fn negate(self, space: ColorSpace) -> Color

Produces the complementary color using a provided color space. You can think of it as the opposite side on a color wheel.

#square(fill: yellow)
#square(fill: yellow.negate())
#square(fill: yellow.negate(space: rgb))
Source

pub fn rotate( self, span: Span, angle: Angle, space: ColorSpace, ) -> SourceResult<Color>

Rotates the hue of the color by a given angle.

Source

pub fn mix(colors: Vec<WeightedColor>, space: ColorSpace) -> StrResult<Color>

Create a color by mixing two or more colors.

In color spaces with a hue component (hsl, hsv, oklch), only two colors can be mixed at once. Mixing more than two colors in such a space will result in an error!

#set block(height: 20pt, width: 100%)
#block(fill: red.mix(blue))
#block(fill: red.mix(blue, space: rgb))
#block(fill: color.mix(red, blue, white))
#block(fill: color.mix((red, 70%), (blue, 30%)))
Source

pub fn transparentize(self, scale: Ratio) -> StrResult<Color>

Makes a color more transparent by a given factor.

This method is relative to the existing alpha value. If the scale is positive, calculates alpha - alpha * scale. Negative scales behave like color.opacify(-scale).

#block(fill: red)[opaque]
#block(fill: red.transparentize(50%))[half red]
#block(fill: red.transparentize(75%))[quarter red]
Source

pub fn opacify(self, scale: Ratio) -> StrResult<Color>

Makes a color more opaque by a given scale.

This method is relative to the existing alpha value. If the scale is positive, calculates alpha + scale - alpha * scale. Negative scales behave like color.transparentize(-scale).

#let half-red = red.transparentize(50%)
#block(fill: half-red.opacify(100%))[opaque]
#block(fill: half-red.opacify(50%))[three quarters red]
#block(fill: half-red.opacify(-50%))[one quarter red]
Source§

impl Color

Source

pub fn mix_iter( colors: impl IntoIterator<Item = WeightedColor, IntoIter = impl ExactSizeIterator<Item = WeightedColor>>, space: ColorSpace, ) -> StrResult<Color>

Same as Color::mix, but takes an iterator instead of a vector.

Source

pub fn from_u8(r: u8, g: u8, b: u8, a: u8) -> Self

Construct a new RGBA color from 8-bit values.

Source

pub fn from_u32(color: u32) -> Self

Converts a 32-bit integer to an RGBA color.

Source

pub fn alpha(&self) -> Option<f32>

Returns the alpha channel of the color, if it has one.

Source

pub fn with_alpha(self, alpha: f32) -> Self

Sets the alpha channel of the color, if it has one.

Source

pub fn to_vec4(&self) -> [f32; 4]

Converts the color to a vec of four floats.

Source

pub fn to_vec4_u8(&self) -> [u8; 4]

Converts the color to a vec of four u8s.

Source

pub fn to_space(self, space: ColorSpace) -> Self

Source

pub fn to_luma(self) -> Self

Source

pub fn to_oklab(self) -> Self

Source

pub fn to_oklch(self) -> Self

Source

pub fn to_rgb(self) -> Self

Source

pub fn to_linear_rgb(self) -> Self

Source

pub fn to_cmyk(self) -> Self

Source

pub fn to_hsl(self) -> Self

Source

pub fn to_hsv(self) -> Self

Trait Implementations§

Source§

impl Clone for Color

Source§

fn clone(&self) -> Color

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Color

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Alpha<Hsl, f32>> for Color

Source§

fn from(c: Hsl) -> Self

Converts to this type from the input type.
Source§

impl From<Alpha<Hsv, f32>> for Color

Source§

fn from(c: Hsv) -> Self

Converts to this type from the input type.
Source§

impl From<Alpha<Luma, f32>> for Color

Source§

fn from(c: Luma) -> Self

Converts to this type from the input type.
Source§

impl From<Alpha<Oklab, f32>> for Color

Source§

fn from(c: Oklab) -> Self

Converts to this type from the input type.
Source§

impl From<Alpha<Oklch, f32>> for Color

Source§

fn from(c: Oklch) -> Self

Converts to this type from the input type.
Source§

impl From<Alpha<Rgb<Linear<Srgb>>, f32>> for Color

Source§

fn from(c: LinearRgb) -> Self

Converts to this type from the input type.
Source§

impl From<Alpha<Rgb, f32>> for Color

Source§

fn from(c: Rgb) -> Self

Converts to this type from the input type.
Source§

impl From<Cmyk> for Color

Source§

fn from(c: Cmyk) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Color

Source§

fn from_str(hex_str: &str) -> Result<Self, Self::Err>

Constructs a new color from hex strings like the following:

  • #aef (shorthand, with leading hash),
  • 7a03c2 (without alpha),
  • abcdefff (with alpha).

The hash is optional and both lower and upper case are fine.

Source§

type Err = &'static str

The associated error which can be returned from parsing.
Source§

impl FromValue for Color

Source§

fn from_value(value: Value) -> HintedStrResult<Self>

Try to cast the value into an instance of Self.
Source§

impl Hash for Color

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IntoValue for Color

Source§

fn into_value(self) -> Value

Cast this type into a value.
Source§

impl NativeScope for Color

Source§

fn constructor() -> Option<&'static NativeFuncData>

The constructor function for the type, if any.
Source§

fn scope() -> Scope

Get the associated scope for the type.
Source§

impl NativeType for Color

Source§

const NAME: &'static str = "color"

The type’s name. Read more
Source§

fn data() -> &'static NativeTypeData

Source§

fn ty() -> Type

Get the type for the native Rust type.
Source§

impl PartialEq for Color

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Reflect for Color

Source§

fn input() -> CastInfo

Describe what can be cast into this value.
Source§

fn output() -> CastInfo

Describe what this value can be cast into.
Source§

fn castable(value: &Value) -> bool

Whether the given value can be converted to T. Read more
Source§

fn error(found: &Value) -> HintedString

Produce an error message for an unacceptable value type. Read more
Source§

impl Repr for Color

Source§

fn repr(&self) -> EcoString

Return the debug representation of the value.
Source§

impl Copy for Color

Source§

impl Eq for Color

Auto Trait Implementations§

§

impl Freeze for Color

§

impl RefUnwindSafe for Color

§

impl Send for Color

§

impl Sync for Color

§

impl Unpin for Color

§

impl UnwindSafe for Color

Blanket Implementations§

Source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Real + Zero + Arithmetics + Clone, Swp: WhitePoint<T>, Dwp: WhitePoint<T>, D: AdaptFrom<S, Swp, Dwp, T>,

Source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<T>,

Convert the source color to the destination color using the specified method.
Source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default.
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, C> ArraysFrom<C> for T
where C: IntoArrays<T>,

Source§

fn arrays_from(colors: C) -> T

Cast a collection of colors into a collection of arrays.
Source§

impl<T, C> ArraysInto<C> for T
where C: FromArrays<T>,

Source§

fn arrays_into(self) -> C

Cast this collection of arrays into a collection of colors.
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for U
where T: FromCam16Unclamped<WpParam, U>,

Source§

type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T, C> ComponentsFrom<C> for T
where C: IntoComponents<T>,

Source§

fn components_from(colors: C) -> T

Cast a collection of colors into a collection of color components.
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromAngle<T> for T

Source§

fn from_angle(angle: T) -> T

Performs a conversion from angle.
Source§

impl<T, U> FromStimulus<U> for T
where U: IntoStimulus<T>,

Source§

fn from_stimulus(other: U) -> T

Converts other into Self, while performing the appropriate scaling, rounding and clamping.
Source§

impl<T> FromValue<Spanned<Value>> for T
where T: FromValue,

Source§

fn from_value(value: Spanned<Value>) -> Result<T, HintedString>

Try to cast the value into an instance of Self.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> IntoAngle<U> for T
where U: FromAngle<T>,

Source§

fn into_angle(self) -> U

Performs a conversion into T.
Source§

impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for U
where T: Cam16FromUnclamped<WpParam, U>,

Source§

type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<T, U> IntoColor<U> for T
where U: FromColor<T>,

Source§

fn into_color(self) -> U

Convert into T with values clamped to the color defined bounds Read more
Source§

impl<T, U> IntoColorUnclamped<U> for T
where U: FromColorUnclamped<T>,

Source§

fn into_color_unclamped(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoResult for T
where T: IntoValue,

Source§

fn into_result(self, _: Span) -> Result<Value, EcoVec<SourceDiagnostic>>

Cast this type into a value.
Source§

impl<T> IntoStimulus<T> for T

Source§

fn into_stimulus(self) -> T

Converts self into T, while performing the appropriate scaling, rounding and clamping.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, C> TryComponentsInto<C> for T
where C: TryFromComponents<T>,

Source§

type Error = <C as TryFromComponents<T>>::Error

The error for when try_into_colors fails to cast.
Source§

fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>

Try to cast this collection of color components into a collection of colors. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> TryIntoColor<U> for T
where U: TryFromColor<T>,

Source§

fn try_into_color(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
Source§

impl<C, U> UintsFrom<C> for U
where C: IntoUints<U>,

Source§

fn uints_from(colors: C) -> U

Cast a collection of colors into a collection of unsigned integers.
Source§

impl<C, U> UintsInto<C> for U
where C: FromUints<U>,

Source§

fn uints_into(self) -> C

Cast this collection of unsigned integers into a collection of colors.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T
where T: Send + Sync,