pub struct Color {
pub red: u8,
pub green: u8,
pub blue: u8,
}
Expand description
Representation of the <color>
type.
Fields§
§red: u8
§green: u8
§blue: u8
Implementations§
Source§impl Color
impl Color
Sourcepub fn new(red: u8, green: u8, blue: u8) -> Color
pub fn new(red: u8, green: u8, blue: u8) -> Color
Constructs a new Color
from red
, green
and blue
values.
Sourcepub fn from_span(span: StrSpan<'_>) -> Result<Color, StreamError>
pub fn from_span(span: StrSpan<'_>) -> Result<Color, StreamError>
Parses Color
from StrSpan
.
Parsing is done according to spec:
color ::= "#" hexdigit hexdigit hexdigit (hexdigit hexdigit hexdigit)?
| "rgb(" wsp* integer comma integer comma integer wsp* ")"
| "rgb(" wsp* integer "%" comma integer "%" comma integer "%" wsp* ")"
| color-keyword
hexdigit ::= [0-9A-Fa-f]
comma ::= wsp* "," wsp*
* The SVG spec has an error. There should be number
,
not an integer
for percent values (details).
§Errors
-
Returns error if a color has an invalid format.
-
Returns error if
color-keyword
orrgb
prefix are in in the lowercase. It’s not supported. -
Returns error if
<color>
is followed by<icccolor>
. It’s not supported.
§Notes
- Any non-
hexdigit
bytes will be treated as0
. - Allocates heap memory for case-insensitive named colors comparison.
Trait Implementations§
impl Copy for Color
impl StructuralPartialEq 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<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more