Struct colorsys::Rgb

source ·
pub struct Rgb { /* private fields */ }
Expand description

The RGB color model.

Has red, green, blue and optional alpha channel fields. Red, green, blue values are stored between 0.0 and 255.0, alpha is between 0.0 and 1.0. If inputted or received values are exceeds the allowed value, or is less than zero it will be equalize to limit.

Example

use colorsys::{Rgb, Hsl, prelude::*};
let mut rgb1 = Rgb::from((100.0, 255.0, 17.0));
// Rgb { r: 100.0, g: 255.0, b: 17.0, a: None }

let green = rgb1.green();
// 255.0

rgb1.set_red(108.3);
// Rgb { r: 108.3, g: 255.0, b: 17.0, .. }

let mut hsl: Hsl = rgb1.into();
// ~Hsl { h: 96.98, s: 100.0, l: 53.333, .. }

hsl.saturate( SaturationInSpace::Hsl(-57.901) );
// ~Hsl { h: 96.98, s: 42.099, l: 53.333, .. }

let mut rgb2 = Rgb::from(&hsl);
// ~Rgb { r: 124.34, g: 186.1, b: 85.9, .. }

let rgb2tuple: (f64,f64,f64) = rgb2.as_ref().into();
// (124.34, 186.1,85.9)

rgb2 += Rgb::from_hex_str("#35f15b").unwrap();;
// ~Rgb { r: 177.33, g: 255.0, b: 176.902, .. }

rgb2.set_green(-150.0);
assert_eq!(rgb2.green(), 0.0);

rgb2.lighten(-13.123);
// ~Rgb { r: 110.41, g: 0.0, b: 110.1, .. }

rgb2.grayscale_simple();
// ~Rgb { r: 55.2, g: 55.2, b: 55.2, .. }

let css_string = rgb2.to_css_string();
assert_eq!(css_string, "rgb(55,55,55)");

Implementations§

👎Deprecated since 0.7.0: Please use red instead
👎Deprecated since 0.7.0: Please use green instead
👎Deprecated since 0.7.0: Please use blue instead

Returns a String that can be used in CSS.

Example
use colorsys::{Rgb};

let rgb = Rgb::from([55.0,31.1, 201.9]);
assert_eq!(rgb.to_css_string(), "rgb(55,31,202)");

Returns an iterator over three color units and the possibly alpha value.

Returns an RGB representation with values converted to floar from 0.0 to 1.0

Trait Implementations§

The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
Performs the += operation. Read more
Converts this type into a shared reference of the (usually inferred) input type.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Lighten or darken color. amt is a percent with negative values - -100..100

Example
use colorsys::{Rgb,ColorTransform, ColorTuple};
let tuple = (30.0, 108.0, 77.0);
let mut rgb = Rgb::from(&tuple);

rgb.lighten(20.0);
assert_eq!(rgb.to_css_string(), "rgb(52,188,134)" );

rgb.lighten(-20.0);
assert_eq!(rgb.to_css_string(), "rgb(30,108,77)" );

rgb.lighten(-20.0);
assert_eq!(rgb.to_css_string(), "rgb(8,28,20)" );

rgb.lighten(301.123);
assert_eq!(rgb.to_css_string(), "rgb(255,255,255)" );
Saturate/desaturate color. Value is percent: -100..100. You need specify in what color space you want to increase/decrease saturation.
increase/decrease color tone. Value is degree - -360..360.
Brings color to a shade of gray. For more specific grayscale methods see Rgb.grayscale
Just inverts color
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Example
use colorsys::{Rgb,Hsl,prelude::*};
let hsl = Hsl::from(&(48.0, 70.0, 50.0));
let rgb: Rgb = Rgb::from(&hsl);
assert_eq!(rgb.to_css_string(), "rgb(217,181,38)");
Converts to this type from the input type.
Converts to this type from the input type.
Example
use colorsys::{Rgb,Hsl,prelude::*};
let rgb = Rgb::from(&(215.0, 231.0, 236.0));
let hsl = Hsl::from(&rgb);
assert_eq!(hsl.to_css_string(), "hsl(194,36%,88%)");
Converts to this type from the input type.
Converts to this type from the input type.
Example
use colorsys::{Rgb,Hsl,prelude::*};
let mut hsl = Hsl::from(&(359.0, 33.0, 77.0));
let rgb_string = Rgb::from(&mut hsl).to_css_string();
assert_eq!(rgb_string, "rgb(216,177,178)");
Converts to this type from the input type.
Example
use colorsys::{Rgb,Hsl,prelude::*};
let mut rgb = Rgb::from(&(0.0, 0.0, 0.0));
let hsl_string = Hsl::from(&mut rgb).to_css_string();
assert_eq!(hsl_string, "hsl(0,0%,0%)");
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Example
use colorsys::{Rgb,Hsl,prelude::*};
let hsl = Hsl::from(&(192.0, 67.0, 28.0));
let rgb_string = Rgb::from(hsl).to_css_string();
assert_eq!(rgb_string, "rgb(24,100,119)");
Converts to this type from the input type.
Converts to this type from the input type.
Example
use colorsys::{Rgb,Hsl,prelude::*};
let rgb = Rgb::from(&(255.0, 255.0, 255.0));
let hsl_string = Hsl::from(rgb).to_css_string();
assert_eq!(hsl_string, "hsl(0,0%,100%)");
Converts to this type from the input type.
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
Performs the -= operation. 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.