Enum lifxi::http::Color

source ·
pub enum Color {
Show 16 variants Red, Orange, Yellow, Green, Blue, Purple, Pink, White, Hue(u16), Saturation(f32), Brightness(f32), Kelvin(u16), Hsbk(Option<u16>, Option<f32>, Option<f32>, Option<u16>), Rgb([u8; 3]), RgbStr(String), Custom(String),
}
Expand description

Specifies the desired color setting of a light.

HSBK is the preferred method of specifying colors (RGB represents color poorly); as such, Hue, Saturation, Brightness, and Kelvin are among the more useful variants here.

RGB colors will automatically be converted by the API.

Variants

Red

Sets the hue and saturation components necessary to change the color to red, leaving brightness untouched.

Orange

Sets the hue and saturation components necessary to change the color to orange, leaving brightness untouched.

Yellow

Sets the hue and saturation components necessary to change the color to yellow, leaving brightness untouched.

Green

Sets the hue and saturation components necessary to change the color to green, leaving brightness untouched.

Blue

Sets the hue and saturation components necessary to change the color to blue, leaving brightness untouched.

Purple

Sets the hue and saturation components necessary to change the color to purple, leaving brightness untouched.

Pink

Sets the hue and saturation components necessary to change the color to pink, leaving brightness untouched.

White

Sets the hue and saturation components necessary to change the color to white, leaving brightness untouched.

Hue(u16)

Sets the hue, leaving all else untouched.

The hue should be between 0 and 360.

Saturation(f32)

Sets the saturation, leaving all else untouched.

The saturation should be between 0 and 1.

Brightness(f32)

Sets the brightness, leaving all else untouched.

The brightness should be between 0 and 1.

Kelvin(u16)

Sets the temperature to the given value and saturation to 0, leaving all else untouched.

The temperature should be between 1500 and 9000.

Hsbk(Option<u16>, Option<f32>, Option<f32>, Option<u16>)

Used to specify more than one of hue, saturation, brightness, and color temperature.

See Hue, Saturation, Brightness, and Kelvin. None values are ignored.

Rgb([u8; 3])

Sets the color to an RGB color using the given numeric components.

It is preferred to use this over RgbStr where posssible.

RgbStr(String)

Sets the color to an RGB color using the given specifier string.

Strings may be of the form #ff0000 or ff0000; outputs will be normalized to the former.

It is preferred to use Rgb instead of this where posssible.

Custom(String)

Uses a custom specifier string.

This option exists for undocumented features. For instance, “cyan” is a valid color choice, but it is undocumented and therefore (theoretically) unstable, so it is not officially/ supported by this crate.

Implementations

Checks whether the color is valid.

Notes

Custom color strings are not validated.

Examples
use lifxi::http::Color;
// Too short
let setting = Color::RgbStr("".to_string());
assert!(setting.validate().is_err());
// Too long for no leading #
let setting = Color::RgbStr("1234567".to_string());
assert!(setting.validate().is_err());
// Too high (max 9000)
let setting = Color::Kelvin(10_000);
assert!(setting.validate().is_err());
// Too high (max 1.0)
let setting = Color::Brightness(1.2);
assert!(setting.validate().is_err());
// Too low (min 0.0)
let setting = Color::Saturation(-0.1);
assert!(setting.validate().is_err());
let setting = Color::Kelvin(2_000);
assert!(setting.validate().is_ok());

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
Deserialize this value from the given Serde deserializer. Read more
Formats the value using the given formatter. Read more

Parses the color string into a color setting.

Notes

Custom colors cannot be made with this method; use Color::Custom(s) instead.

The associated error which can be returned from parsing.
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
Serialize this value into the given Serde serializer. 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
Converts the given value to a String. 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.