Struct http_halforms::Hal

source ·
pub struct Hal {
    pub links: BTreeMap<String, SingleOrMultiple<Link>>,
    pub embedded: BTreeMap<String, SingleOrMultiple<Hal>>,
    pub templates: BTreeMap<String, Template>,
    pub payload: Value,
}
Expand description

Representation of a HAL document.

Fields§

§links: BTreeMap<String, SingleOrMultiple<Link>>§embedded: BTreeMap<String, SingleOrMultiple<Hal>>§templates: BTreeMap<String, Template>§payload: Value

Implementations§

Create a new HAL document for the given payload value.

Panics

This will panic if the value provided can not be serialized into JSON for some reason.

Examples found in repository?
src/response.rs (line 138)
133
134
135
136
137
138
139
140
141
142
pub fn new<V>(value: V) -> HalResponse
where
    V: Serialize,
{
    HalResponse {
        hal:         Hal::new(value),
        status_code: StatusCode::OK,
        headers:     HeaderMap::default(),
    }
}

Add a new link to a HAL document.

Examples found in repository?
src/response.rs (line 23)
18
19
20
21
22
23
24
25
26
    pub fn with_link<N, L>(mut self, name: N, link: L) -> Self
    where
        N: ToString,
        L: Into<Link>,
    {
        self.hal = self.hal.with_link(name, link);

        self
    }
More examples
Hide additional examples
src/hal/hal.rs (line 75)
69
70
71
72
73
74
75
76
77
78
79
    pub fn maybe_with_link<N, L>(self, name: N, link: Option<L>) -> Self
    where
        N: ToString,
        L: Into<Link>,
    {
        if let Some(link) = link {
            self.with_link(name, link)
        } else {
            self
        }
    }

Add a new link to a HAL document.

Examples found in repository?
src/response.rs (line 35)
30
31
32
33
34
35
36
37
38
    pub fn maybe_with_link<N, L>(mut self, name: N, link: Option<L>) -> Self
    where
        N: ToString,
        L: Into<Link>,
    {
        self.hal = self.hal.maybe_with_link(name, link);

        self
    }

Add a new embedded HAL document to the HAL document.

Examples found in repository?
src/response.rs (line 47)
42
43
44
45
46
47
48
49
50
    pub fn with_embedded<N, H>(mut self, name: N, value: H) -> Self
    where
        N: ToString,
        H: Into<Hal>,
    {
        self.hal = self.hal.with_embedded(name, value);

        self
    }
More examples
Hide additional examples
src/hal/hal.rs (line 109)
103
104
105
106
107
108
109
110
111
112
113
    pub fn maybe_with_embedded<N, L>(self, name: N, embedded: Option<L>) -> Self
    where
        N: ToString,
        L: Into<Hal>,
    {
        if let Some(embedded) = embedded {
            self.with_embedded(name, embedded)
        } else {
            self
        }
    }

Add a new embedded HAL document to a HAL document.

Examples found in repository?
src/response.rs (line 59)
54
55
56
57
58
59
60
61
62
    pub fn maybe_with_embedded<N, H>(mut self, name: N, value: Option<H>) -> Self
    where
        N: ToString,
        H: Into<Hal>,
    {
        self.hal = self.hal.maybe_with_embedded(name, value);

        self
    }

Add a new action template to the HAL-FORMS document.

Examples found in repository?
src/response.rs (line 71)
66
67
68
69
70
71
72
73
74
    pub fn with_template<N, T>(mut self, name: N, value: T) -> Self
    where
        N: ToString,
        T: Into<Template>,
    {
        self.hal = self.hal.with_template(name, value);

        self
    }
More examples
Hide additional examples
src/hal/hal.rs (line 135)
129
130
131
132
133
134
135
136
137
138
139
    pub fn maybe_with_template<N, T>(self, name: N, template: Option<T>) -> Self
    where
        N: ToString,
        T: Into<Template>,
    {
        if let Some(template) = template {
            self.with_template(name, template)
        } else {
            self
        }
    }

Add a new action template to the HAL-FORMS document.

Examples found in repository?
src/response.rs (line 83)
78
79
80
81
82
83
84
85
86
    pub fn maybe_with_template<N, T>(mut self, name: N, template: Option<T>) -> Self
    where
        N: ToString,
        T: Into<Template>,
    {
        self.hal = self.hal.maybe_with_template(name, template);

        self
    }

Trait Implementations§

Formats the value using the given formatter. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.