style/values/generics/
url.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5//! Generic types for url properties.
6
7use crate::derives::*;
8
9/// An image url or none, used for example in list-style-image
10#[derive(
11    Animate,
12    Clone,
13    ComputeSquaredDistance,
14    Debug,
15    MallocSizeOf,
16    PartialEq,
17    Parse,
18    SpecifiedValueInfo,
19    ToAnimatedValue,
20    ToAnimatedZero,
21    ToComputedValue,
22    ToCss,
23    ToResolvedValue,
24    ToShmem,
25    ToTyped,
26)]
27#[repr(C, u8)]
28pub enum GenericUrlOrNone<U> {
29    /// `none`
30    None,
31    /// A URL.
32    Url(U),
33}
34
35pub use self::GenericUrlOrNone as UrlOrNone;
36
37impl<Url> UrlOrNone<Url> {
38    /// Initial "none" value for properties such as `list-style-image`
39    pub fn none() -> Self {
40        UrlOrNone::None
41    }
42
43    /// Returns whether the value is `none`.
44    pub fn is_none(&self) -> bool {
45        match *self {
46            UrlOrNone::None => true,
47            UrlOrNone::Url(..) => false,
48        }
49    }
50}