Skip to main content

lux_lib/rockspec/
description.rs

1use serde::Deserialize;
2use url::Url;
3
4/// A rock's metadata, to be displayed on the remote package server
5#[derive(Clone, Deserialize, Debug, PartialEq, Default, lux_macros::AsLuaKV)]
6#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
7#[display_lua(key = "description")]
8pub struct Spec {
9    /// A one-line description of the package.
10    pub summary: Option<String>,
11    /// A longer description of the package.
12    pub detailed: Option<String>,
13    /// The license used by the package.
14    pub license: Option<String>,
15    /// An URL for the project. This is not the URL for the tarball, but the address of a website.
16    #[serde(default, deserialize_with = "deserialize_url")]
17    #[cfg_attr(feature = "schema", schemars(with = "Option<String>"))]
18    pub homepage: Option<Url>,
19    /// An URL for the project's issue tracker.
20    #[serde(default, deserialize_with = "deserialize_url")]
21    #[cfg_attr(feature = "schema", schemars(with = "Option<String>"))]
22    pub issues_url: Option<Url>,
23    /// Contact information for the rockspec maintainer.
24    pub maintainer: Option<String>,
25    /// A list of short strings that specify labels for categorization of this rock.
26    #[serde(default)]
27    pub labels: Vec<String>,
28}
29
30fn deserialize_url<'de, D>(deserializer: D) -> Result<Option<Url>, D::Error>
31where
32    D: serde::Deserializer<'de>,
33{
34    let s = Option::<String>::deserialize(deserializer)?;
35    s.map(|s| Url::parse(&s).map_err(serde::de::Error::custom))
36        .transpose()
37}