Version

Struct Version 

Source
pub struct Version { /* private fields */ }

Implementations§

Source§

impl Version

Source

pub fn new(minor: u64) -> Self

Examples found in repository?
examples/builders.rs (line 6)
4fn main() {
5    let document = jsonapis::DocumentBuilder::default()
6        .jsonapi(jsonapis::Version::new(0))
7        .meta1("current_page", 1)
8        .meta1("items_per_page", 2)
9        .meta1("total_pages", 3)
10        .meta1("total_items", 6)
11        .link("self", "http://example.com/posts.json?page=1")
12        .link("first", "http://example.com/posts.json?page=1")
13        .link("last", "http://example.com/posts.json?page=3")
14        .link("next", "http://example.com/posts.json?page=2")
15        .data(vec![
16            jsonapis::ResourceBuilder::new_with_id("posts", "1")
17                .link("self", "http://example.com/posts/1.json")
18                .attr("title", "Some blog post")
19                .attr("summary", "Here is the beginning of some blog post.")
20                .rel(
21                    "author",
22                    jsonapis::ResourceBuilder::new_with_id("users", "1")
23                        .link("self", "http://example.com/users/1.json")
24                        .attr("username", "alice"),
25                ),
26            jsonapis::ResourceBuilder::new_with_id("posts", "2")
27                .link("self", "http://example.com/posts/2.json")
28                .attr("title", "Other blog post")
29                .attr("summary", "Here is the beginning of other blog post.")
30                .rel(
31                    "author",
32                    jsonapis::ResourceBuilder::new_with_id("users", "2")
33                        .link("self", "http://example.com/users/2.json")
34                        .attr("username", "bob"),
35                ),
36        ])
37        .unwrap();
38
39    let expected_value = json!({
40        "jsonapi": json!({
41            "version": json!("1.0"),
42            "meta": json!(null),
43        }),
44        "meta": json!({
45            "current_page": json!(1),
46            "items_per_page": json!(2),
47            "total_pages": json!(3),
48            "total_items": json!(6),
49        }),
50        "links": json!({
51            "self": json!("http://example.com/posts.json?page=1"),
52            "related": json!(null),
53            "first": json!("http://example.com/posts.json?page=1"),
54            "last": json!("http://example.com/posts.json?page=3"),
55            "prev": json!(null),
56            "next": json!("http://example.com/posts.json?page=2"),
57            "about": json!(null),
58        }),
59        "data": json!([
60            json!({
61                "type": json!("posts"),
62                "id": json!("1"),
63                "meta": json!(null),
64                "links": json!({
65                    "self": json!("http://example.com/posts/1.json"),
66                    "related": json!(null),
67                    "first": json!(null),
68                    "last": json!(null),
69                    "prev": json!(null),
70                    "next": json!(null),
71                    "about": json!(null),
72                }),
73                "attributes": json!({
74                    "title": json!("Some blog post"),
75                    "summary": json!("Here is the beginning of some blog post."),
76                }),
77                "relationships": json!({
78                    "author": json!({
79                        "meta": json!(null),
80                        "links": json!(null),
81                        "data": json!({
82                            "type": json!("users"),
83                            "id": json!("1"),
84                            "meta": json!(null),
85                            "links": json!({
86                                "self": json!("http://example.com/users/1.json"),
87                                "related": json!(null),
88                                "first": json!(null),
89                                "last": json!(null),
90                                "prev": json!(null),
91                                "next": json!(null),
92                                "about": json!(null),
93                            }),
94                            "attributes": json!({
95                                "username": json!("alice"),
96                            }),
97                            "relationships": json!(null),
98                        }),
99                    }),
100                }),
101            }),
102            json!({
103                "type": json!("posts"),
104                "id": json!("2"),
105                "meta": json!(null),
106                "links": json!({
107                    "self": json!("http://example.com/posts/2.json"),
108                    "related": json!(null),
109                    "first": json!(null),
110                    "last": json!(null),
111                    "prev": json!(null),
112                    "next": json!(null),
113                    "about": json!(null),
114                }),
115                "attributes": json!({
116                    "title": json!("Other blog post"),
117                    "summary": json!("Here is the beginning of other blog post."),
118                }),
119                "relationships": json!({
120                    "author": json!({
121                        "meta": json!(null),
122                        "links": json!(null),
123                        "data": json!({
124                            "type": json!("users"),
125                            "id": json!("2"),
126                            "meta": json!(null),
127                            "links": json!({
128                                "self": json!("http://example.com/users/2.json"),
129                                "related": json!(null),
130                                "first": json!(null),
131                                "last": json!(null),
132                                "prev": json!(null),
133                                "next": json!(null),
134                                "about": json!(null),
135                            }),
136                            "attributes": json!({
137                                "username": json!("bob"),
138                            }),
139                            "relationships": json!(null),
140                        }),
141                    }),
142                }),
143            }),
144        ]),
145        "errors": json!(null),
146    });
147
148    let actual_json = serde_json::to_string(&document).unwrap();
149
150    let actual_value: Value = serde_json::from_str(&actual_json).unwrap();
151
152    println!("{:#?}", actual_value);
153
154    assert_eq!(actual_value, expected_value);
155}

Trait Implementations§

Source§

impl AsRef<str> for Version

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Version

Source§

fn clone(&self) -> Version

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Version

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Version

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Version

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Version

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Version> for JsonApiBuilder

Source§

fn from(version: Version) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Version

Source§

type Err = ()

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Ord for Version

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Version

Source§

fn eq(&self, other: &Version) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Version

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Version

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Entity<'_> for Version

Source§

impl Eq for Version

Source§

impl StructuralPartialEq for Version

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,