Skip to main content

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)]
28#[typed(todo_derive_fields)]
29pub enum GenericUrlOrNone<U> {
30    /// `none`
31    None,
32    /// A URL.
33    Url(U),
34}
35
36pub use self::GenericUrlOrNone as UrlOrNone;
37
38impl<Url> UrlOrNone<Url> {
39    /// Initial "none" value for properties such as `list-style-image`
40    pub fn none() -> Self {
41        UrlOrNone::None
42    }
43
44    /// Returns whether the value is `none`.
45    pub fn is_none(&self) -> bool {
46        match *self {
47            UrlOrNone::None => true,
48            UrlOrNone::Url(..) => false,
49        }
50    }
51}