/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Generic types for CSS values that are composed of four sides.
usecrate::parser::{Parse, ParserContext}; use cssparser::Parser; use std::fmt::{self, Write}; use style_traits::{CssWriter, ParseError, ToCss};
/// A CSS value made of four components, where its `ToCss` impl will try to /// serialize as few components as possible, like for example in `border-width`. #[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
Deserialize,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
Serialize,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToResolvedValue,
ToShmem,
)] #[repr(C)] pubstruct Rect<T>(pub T, pub T, pub T, pub T);
impl<T> Rect<T> where
T: Clone,
{ /// Returns a rect with all the values equal to `v`. pubfn all(v: T) -> Self {
Rect::new(v.clone(), v.clone(), v.clone(), v)
}
/// Parses a new `Rect<T>` value with the given parse function. pubfn parse_with<'i, 't, Parse>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
parse: Parse,
) -> Result<Self, ParseError<'i>> where
Parse: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result<T, ParseError<'i>>,
{ let first = parse(context, input)?; let second = iflet Ok(second) = input.try_parse(|i| parse(context, i)) {
second
} else { // <first> return Ok(Self::new(
first.clone(),
first.clone(),
first.clone(),
first,
));
}; let third = iflet Ok(third) = input.try_parse(|i| parse(context, i)) {
third
} else { // <first> <second> return Ok(Self::new(first.clone(), second.clone(), first, second));
}; let fourth = iflet Ok(fourth) = input.try_parse(|i| parse(context, i)) {
fourth
} else { // <first> <second> <third> return Ok(Self::new(first, second.clone(), third, second));
}; // <first> <second> <third> <fourth>
Ok(Self::new(first, second, third, fourth))
}
/// Parses a new `Rect<T>` value which all components must be specified, with the given parse /// function. pubfn parse_all_components_with<'i, 't, Parse>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
parse: Parse,
) -> Result<Self, ParseError<'i>> where
Parse: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result<T, ParseError<'i>>,
{ let first = parse(context, input)?; let second = parse(context, input)?; let third = parse(context, input)?; let fourth = parse(context, input)?; // <first> <second> <third> <fourth>
Ok(Self::new(first, second, third, fourth))
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.