diff --git a/internal/app/rustdoc.go b/internal/app/rustdoc.go index 4d66ecf..1b5bddd 100644 --- a/internal/app/rustdoc.go +++ b/internal/app/rustdoc.go @@ -193,6 +193,74 @@ func cleanRustDocHeading(text string) string { return strings.TrimSpace(text) } +// cleanRustDocSignature normalizes an impl/method signature extracted from a +// docs.rs code-header via RawInnerText. It drops the "ⓘ" notable-trait marker +// and flattens the internal newlines/tabs (e.g. from a where clause) into a +// single spaced line so the signature fits in an inline code span. +func cleanRustDocSignature(text string) string { + text = strings.ReplaceAll(text, "ⓘ", "") + text = strings.ReplaceAll(text, "\n", " ") + text = strings.ReplaceAll(text, "\t", " ") + for strings.Contains(text, " ") { + text = strings.ReplaceAll(text, " ", " ") + } + return strings.TrimSpace(text) +} + +// writeRustDocBlock renders the full content of a div.docblock (paragraphs, +// code blocks, lists and headings) into builder, prefixing every line with +// indent so it nests under the enclosing item bullet. This mirrors the content +// types the top-level overview matchers handle, so method, enum-variant and +// struct-field docs no longer silently drop examples, lists or headings. +// Headings are emitted as bold text rather than "#" headings to avoid clashing +// with the document's section structure. +func writeRustDocBlock(builder *strings.Builder, docblock *html.Node, indent string) { + headerMatcher := dq.NewNodeMatcher( + dq.NewMatchFunc("h1,h2,h3,h4,h5,h6"), + func(n *html.Node) { + text := cleanRustDocHeading(dq.InnerText(n, true)) + if text != "" { + builder.WriteString(fmt.Sprintf("%s**%s**\n", indent, text)) + } + }, + ) + pMatcher := dq.NewNodeMatcher( + dq.NewMatchFunc("p"), + func(n *html.Node) { + text := strings.TrimSpace(dq.InnerText(n, true)) + if text != "" { + builder.WriteString(fmt.Sprintf("%s%s\n", indent, text)) + } + }, + ) + preMatcher := dq.NewNodeMatcher( + dq.NewMatchFunc("pre"), + func(n *html.Node) { + code := strings.TrimRight(dq.RawInnerText(n, true), "\n") + builder.WriteString(indent + "```\n") + for _, line := range strings.Split(code, "\n") { + builder.WriteString(indent + line + "\n") + } + builder.WriteString(indent + "```\n") + }, + ) + listMatcher := dq.NewNodeMatcher( + dq.NewMatchFunc("ul,ol"), + nil, + dq.NewNodeMatcher( + dq.NewMatchFunc("li"), + func(n *html.Node) { + text := strings.TrimSpace(dq.InnerText(n, true)) + if text != "" { + builder.WriteString(fmt.Sprintf("%s- %s\n", indent, text)) + } + }, + ), + ) + + dq.Traverse(docblock, []dq.Matcher{headerMatcher, pMatcher, preMatcher, listMatcher}) +} + func parseDocsRsSearchResult(doc *html.Node) (bool, string) { builder := strings.Builder{} @@ -259,6 +327,15 @@ func parseDocsRsSearchResult(doc *html.Node) (bool, string) { func parseDocsRsDocument(doc *html.Node) (bool, string) { builder := strings.Builder{} + // Struct fields (span.structfield) and their docs (a following div.docblock) + // are direct children of section#main-content with no wrapping container, + // unlike the overview docblock (nested in details.top-doc) and method + // docblocks (nested in the impl lists). inFields, toggled by the section + // headers, scopes the top-level div.docblock matcher to the Fields section so + // it doesn't double-emit those other docblocks. fieldOpen pairs each field + // signature with its optional following docblock. + var inFields, fieldOpen bool + // Title from div.main-heading > h1 titleMatcher := dq.NewNodeMatcher( dq.NewMatchFunc("div.main-heading"), @@ -272,6 +349,19 @@ func parseDocsRsDocument(doc *html.Node) (bool, string) { ), ) + // Declaration block: pre.item-decl holds the canonical signature/declaration + // on item pages (struct, enum, fn, trait, type alias). Present on every item + // page and absent on module index pages, so this is a no-op for the latter. + itemDeclMatcher := dq.NewNodeMatcher( + dq.NewMatchFunc("pre.item-decl"), + func(n *html.Node) { + decl := strings.TrimSpace(dq.RawInnerText(n, true)) + if decl != "" { + builder.WriteString(fmt.Sprintf("```rust\n%s\n```\n", decl)) + } + }, + ) + // Matchers for content inside div.docblock docblockHeaderMatcher := dq.NewNodeMatcher( dq.NewMatchFunc("h1,h2,h3,h4,h5,h6"), @@ -332,6 +422,17 @@ func parseDocsRsDocument(doc *html.Node) (bool, string) { dq.NewMatchFunc("h2.section-header"), func(n *html.Node) { text := cleanRustDocHeading(dq.InnerText(n, true)) + // Track whether we're inside the Fields section so the top-level + // div.docblock matcher only fires for field docs. Non-exhaustive + // structs render the header as "Fields (Non-exhaustive)", so match on + // the prefix rather than the exact string. + inFields = strings.HasPrefix(text, "Fields") + // Skip headers whose item lists we deliberately don't expand, so item + // pages don't end with dangling empty sections. + switch text { + case "Auto Trait Implementations", "Blanket Implementations": + return + } builder.WriteString(fmt.Sprintf("\n## %s\n", text)) }, ) @@ -361,6 +462,93 @@ func parseDocsRsDocument(doc *html.Node) (bool, string) { ddMatcher, ) + // Impl blocks on item pages: each impl carries an h3.code-header ("impl Foo") + // and its methods live in section.method > h4.code-header, each followed by a + // div.docblock. Scope to the inherent-impl and trait-impl lists; the auto-trait + // and blanket-impl lists are high-volume noise (Send/Sync/From/…) and are + // intentionally skipped. + implHeaderMatcher := dq.NewNodeMatcher( + dq.NewMatchFunc("h3.code-header"), + func(n *html.Node) { + sig := cleanRustDocSignature(dq.RawInnerText(n, true)) + if sig != "" { + builder.WriteString(fmt.Sprintf("\n### %s\n", sig)) + } + }, + ) + methodSigMatcher := dq.NewNodeMatcher( + dq.NewMatchFunc("h4.code-header"), + func(n *html.Node) { + sig := cleanRustDocSignature(dq.RawInnerText(n, true)) + if sig != "" { + builder.WriteString(fmt.Sprintf("- `%s`\n", sig)) + } + }, + ) + methodDocMatcher := dq.NewNodeMatcher( + dq.NewMatchFunc("div.docblock"), + func(n *html.Node) { + writeRustDocBlock(&builder, n, " ") + }, + ) + implsMatcher := dq.NewNodeMatcher( + dq.NewMatchFunc("div#implementations-list,div#trait-implementations-list"), + nil, + implHeaderMatcher, + methodSigMatcher, + methodDocMatcher, + ) + + // Enum variants: div.variants holds section.variant > h3.code-header (the + // variant signature, e.g. "Number(Number)") each followed by a sibling + // div.docblock. The "## Variants" header itself is already emitted by + // sectionHeaderMatcher. Reuse methodDocMatcher for the variant docs since the + // div.docblock > p shape is identical and the subtrees are disjoint. + variantSigMatcher := dq.NewNodeMatcher( + dq.NewMatchFunc("h3.code-header"), + func(n *html.Node) { + sig := cleanRustDocSignature(dq.RawInnerText(n, true)) + if sig != "" { + builder.WriteString(fmt.Sprintf("- `%s`\n", sig)) + } + }, + ) + variantsMatcher := dq.NewNodeMatcher( + dq.NewMatchFunc("div.variants"), + nil, + variantSigMatcher, + methodDocMatcher, + ) + + // Struct fields: span.structfield > code holds "name: Type"; a documented + // field is followed by a sibling div.docblock. Both are direct children of + // section#main-content, so fieldDocMatcher is gated on inFields (set by the + // Fields section header) to avoid double-emitting the overview/method docblocks. + structFieldMatcher := dq.NewNodeMatcher( + dq.NewMatchFunc("span.structfield"), + func(n *html.Node) { + code := dq.FindOne(n, "code") + if code == nil { + return + } + sig := cleanRustDocSignature(dq.RawInnerText(code, true)) + if sig != "" { + builder.WriteString(fmt.Sprintf("- `%s`\n", sig)) + fieldOpen = true + } + }, + ) + fieldDocMatcher := dq.NewNodeMatcher( + dq.NewMatchFunc("div.docblock"), + func(n *html.Node) { + if !inFields || !fieldOpen { + return + } + fieldOpen = false + writeRustDocBlock(&builder, n, " ") + }, + ) + // Root: section#main-content var matched bool rootMatcher := dq.NewNodeMatcher( @@ -369,9 +557,14 @@ func parseDocsRsDocument(doc *html.Node) (bool, string) { matched = true }, titleMatcher, + itemDeclMatcher, overviewMatcher, sectionHeaderMatcher, itemTableMatcher, + structFieldMatcher, + fieldDocMatcher, + variantsMatcher, + implsMatcher, ) dq.Traverse(doc, []dq.Matcher{rootMatcher}) diff --git a/internal/app/rustdoc_golden_test.go b/internal/app/rustdoc_golden_test.go index c4c911e..2fb502a 100644 --- a/internal/app/rustdoc_golden_test.go +++ b/internal/app/rustdoc_golden_test.go @@ -24,6 +24,22 @@ func TestGolden_parseDocsRsDocument(t *testing.T) { {"serde", "rustdoc_doc_serde.html", "rustdoc_doc_serde.golden"}, {"tokio", "rustdoc_doc_tokio.html", "rustdoc_doc_tokio.golden"}, {"regex", "rustdoc_doc_regex.html", "rustdoc_doc_regex.golden"}, + {"serdejson_map", "rustdoc_doc_serdejson_map.html", "rustdoc_doc_serdejson_map.golden"}, + { + "httparse_request", + "rustdoc_doc_httparse_request.html", + "rustdoc_doc_httparse_request.golden", + }, + { + "serdejson_value", + "rustdoc_doc_serdejson_value.html", + "rustdoc_doc_serdejson_value.golden", + }, + { + "serdejson_tostring", + "rustdoc_doc_serdejson_tostring.html", + "rustdoc_doc_serdejson_tostring.golden", + }, } for _, tt := range tests { diff --git a/internal/app/testdata/rustdoc_doc_httparse_request.golden b/internal/app/testdata/rustdoc_doc_httparse_request.golden new file mode 100644 index 0000000..c69aae6 --- /dev/null +++ b/internal/app/testdata/rustdoc_doc_httparse_request.golden @@ -0,0 +1,68 @@ +# Struct Request +```rust +pub struct Request<'headers, 'buf> { + pub method: Option<&'buf str>, + pub path: Option<&'buf str>, + pub version: Option, + pub headers: &'headers mut [Header<'buf>], +} +``` +A parsed Request. +The optional values will be None if a parse was not complete, and did not +parse the associated property. This allows you to inspect the parts that +could be parsed, before reading more, in case you wish to exit early. + +## Example +``` +let buf = b"GET /404 HTTP/1.1\r\nHost:"; +let mut headers = [httparse::EMPTY_HEADER; 16]; +let mut req = httparse::Request::new(&mut headers); +let res = req.parse(buf).unwrap(); +if res.is_partial() { + match req.path { + Some(ref path) => { + // check router for path. + // /404 doesn't exist? we could stop parsing + }, + None => { + // must read more and parse again + } + } +} +``` + +## Fields +- `method: Option<&'buf str>` + The request method, such as GET . +- `path: Option<&'buf str>` + The request path, such as /about-us . +- `version: Option` + The request minor version, such as 1 for HTTP/1.1 . +- `headers: &'headers mut [Header<'buf>]` + The request headers. + +## Implementations + +### impl<'h, 'b> Request<'h, 'b> +- `pub fn new(headers: &'h mut [Header<'b>]) -> Request<'h, 'b>` + Creates a new Request, using a slice of headers you allocate. +- `pub fn parse_with_uninit_headers( &mut self, buf: &'b [u8], headers: &'h mut [MaybeUninit>], ) -> Result` + Try to parse a buffer of bytes into the Request, +except use an uninitialized slice of Header s. + For more information, see parse +- `pub fn parse(&mut self, buf: &'b [u8]) -> Result` + Try to parse a buffer of bytes into the Request. + Returns byte offset in buf to start of HTTP body. + +## Trait Implementations + +### impl<'headers, 'buf> Debug for Request<'headers, 'buf> +- `fn fmt(&self, f: &mut Formatter<'_>) -> Result` + +### impl<'headers, 'buf> PartialEq for Request<'headers, 'buf> +- `fn eq(&self, other: &Request<'headers, 'buf>) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'headers, 'buf> Eq for Request<'headers, 'buf> + +### impl<'headers, 'buf> StructuralPartialEq for Request<'headers, 'buf> diff --git a/internal/app/testdata/rustdoc_doc_httparse_request.html b/internal/app/testdata/rustdoc_doc_httparse_request.html new file mode 100644 index 0000000..40839a5 --- /dev/null +++ b/internal/app/testdata/rustdoc_doc_httparse_request.html @@ -0,0 +1,272 @@ +Request in httparse - Rust + + + + +
+ + +Skip to main content

Request

Struct Request 

Source
pub struct Request<'headers, 'buf> {
+    pub method: Option<&'buf str>,
+    pub path: Option<&'buf str>,
+    pub version: Option<u8>,
+    pub headers: &'headers mut [Header<'buf>],
+}
Expand description

A parsed Request.

+

The optional values will be None if a parse was not complete, and did not +parse the associated property. This allows you to inspect the parts that +could be parsed, before reading more, in case you wish to exit early.

+

§Example

+
let buf = b"GET /404 HTTP/1.1\r\nHost:";
+let mut headers = [httparse::EMPTY_HEADER; 16];
+let mut req = httparse::Request::new(&mut headers);
+let res = req.parse(buf).unwrap();
+if res.is_partial() {
+    match req.path {
+        Some(ref path) => {
+            // check router for path.
+            // /404 doesn't exist? we could stop parsing
+        },
+        None => {
+            // must read more and parse again
+        }
+    }
+}

Fields§

§method: Option<&'buf str>

The request method, such as GET.

+
§path: Option<&'buf str>

The request path, such as /about-us.

+
§version: Option<u8>

The request minor version, such as 1 for HTTP/1.1.

+
§headers: &'headers mut [Header<'buf>]

The request headers.

+

Implementations§

Source§

impl<'h, 'b> Request<'h, 'b>

Source

pub fn new(headers: &'h mut [Header<'b>]) -> Request<'h, 'b>

Creates a new Request, using a slice of headers you allocate.

+
Source

pub fn parse_with_uninit_headers( + &mut self, + buf: &'b [u8], + headers: &'h mut [MaybeUninit<Header<'b>>], +) -> Result<usize>

Try to parse a buffer of bytes into the Request, +except use an uninitialized slice of Headers.

+

For more information, see parse

+
Source

pub fn parse(&mut self, buf: &'b [u8]) -> Result<usize>

Try to parse a buffer of bytes into the Request.

+

Returns byte offset in buf to start of HTTP body.

+

Trait Implementations§

Source§

impl<'headers, 'buf> Debug for Request<'headers, 'buf>

Source§

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

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

impl<'headers, 'buf> PartialEq for Request<'headers, 'buf>

Source§

fn eq(&self, other: &Request<'headers, 'buf>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'headers, 'buf> Eq for Request<'headers, 'buf>

Source§

impl<'headers, 'buf> StructuralPartialEq for Request<'headers, 'buf>

Auto Trait Implementations§

§

impl<'headers, 'buf> Freeze for Request<'headers, 'buf>

§

impl<'headers, 'buf> RefUnwindSafe for Request<'headers, 'buf>

§

impl<'headers, 'buf> Send for Request<'headers, 'buf>

§

impl<'headers, 'buf> Sync for Request<'headers, 'buf>

§

impl<'headers, 'buf> Unpin for Request<'headers, 'buf>

§

impl<'headers, 'buf> UnsafeUnpin for Request<'headers, 'buf>

§

impl<'headers, 'buf> !UnwindSafe for Request<'headers, 'buf>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

+
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, 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.
\ No newline at end of file diff --git a/internal/app/testdata/rustdoc_doc_serdejson_map.golden b/internal/app/testdata/rustdoc_doc_serdejson_map.golden new file mode 100644 index 0000000..2fbead3 --- /dev/null +++ b/internal/app/testdata/rustdoc_doc_serdejson_map.golden @@ -0,0 +1,281 @@ +# Struct Map +```rust +pub struct Map { /* private fields */ } +``` +Represents a JSON key/value type. + +## Implementations + +### impl Map +- `pub fn new() -> Self` + Makes a new empty Map. +- `pub fn with_capacity(capacity: usize) -> Self` + Makes a new empty Map with the given initial capacity. +- `pub fn clear(&mut self)` + Clears the map, removing all values. +- `pub fn get(&self, key: &Q) -> Option<&Value>where String: Borrow, Q: ?Sized + Ord + Eq + Hash,` + Returns a reference to the value corresponding to the key. + The key may be any borrowed form of the map’s key type, but the ordering +on the borrowed form must match the ordering on the key type. +- `pub fn contains_key(&self, key: &Q) -> boolwhere String: Borrow, Q: ?Sized + Ord + Eq + Hash,` + Returns true if the map contains a value for the specified key. + The key may be any borrowed form of the map’s key type, but the ordering +on the borrowed form must match the ordering on the key type. +- `pub fn get_mut(&mut self, key: &Q) -> Option<&mut Value>where String: Borrow, Q: ?Sized + Ord + Eq + Hash,` + Returns a mutable reference to the value corresponding to the key. + The key may be any borrowed form of the map’s key type, but the ordering +on the borrowed form must match the ordering on the key type. +- `pub fn get_key_value(&self, key: &Q) -> Option<(&String, &Value)>where String: Borrow, Q: ?Sized + Ord + Eq + Hash,` + Returns the key-value pair matching the given key. + The key may be any borrowed form of the map’s key type, but the ordering +on the borrowed form must match the ordering on the key type. +- `pub fn insert(&mut self, k: String, v: Value) -> Option` + Inserts a key-value pair into the map. + If the map did not have this key present, None is returned. + If the map did have this key present, the value is updated, and the old +value is returned. +- `pub fn shift_insert( &mut self, index: usize, k: String, v: Value, ) -> Option` + Insert a key-value pair in the map at the given index. + If the map did not have this key present, None is returned. + If the map did have this key present, the key is moved to the new +position, the value is updated, and the old value is returned. +- `pub fn remove(&mut self, key: &Q) -> Optionwhere String: Borrow, Q: ?Sized + Ord + Eq + Hash,` + Removes a key from the map, returning the value at the key if the key +was previously in the map. + The key may be any borrowed form of the map’s key type, but the ordering +on the borrowed form must match the ordering on the key type. + If serde_json’s “preserve_order” is enabled, .remove(key) is +equivalent to .swap_remove(key) , replacing this +entry’s position with the last element. If you need to preserve the +relative order of the keys in the map, use .shift_remove(key) instead. +- `pub fn remove_entry(&mut self, key: &Q) -> Option<(String, Value)>where String: Borrow, Q: ?Sized + Ord + Eq + Hash,` + Removes a key from the map, returning the stored key and value if the +key was previously in the map. + The key may be any borrowed form of the map’s key type, but the ordering +on the borrowed form must match the ordering on the key type. + If serde_json’s “preserve_order” is enabled, .remove_entry(key) is +equivalent to .swap_remove_entry(key) , +replacing this entry’s position with the last element. If you need to +preserve the relative order of the keys in the map, use .shift_remove_entry(key) instead. +- `pub fn swap_remove(&mut self, key: &Q) -> Optionwhere String: Borrow, Q: ?Sized + Ord + Eq + Hash,` + Removes and returns the value corresponding to the key from the map. + Like Vec::swap_remove , the entry is removed by swapping it with the +last element of the map and popping it off. This perturbs the position +of what used to be the last element! +- `pub fn swap_remove_entry(&mut self, key: &Q) -> Option<(String, Value)>where String: Borrow, Q: ?Sized + Ord + Eq + Hash,` + Remove and return the key-value pair. + Like Vec::swap_remove , the entry is removed by swapping it with the +last element of the map and popping it off. This perturbs the position +of what used to be the last element! +- `pub fn shift_remove(&mut self, key: &Q) -> Optionwhere String: Borrow, Q: ?Sized + Ord + Eq + Hash,` + Removes and returns the value corresponding to the key from the map. + Like Vec::remove , the entry is removed by shifting all of the +elements that follow it, preserving their relative order. This perturbs +the index of all of those elements! +- `pub fn shift_remove_entry(&mut self, key: &Q) -> Option<(String, Value)>where String: Borrow, Q: ?Sized + Ord + Eq + Hash,` + Remove and return the key-value pair. + Like Vec::remove , the entry is removed by shifting all of the +elements that follow it, preserving their relative order. This perturbs +the index of all of those elements! +- `pub fn append(&mut self, other: &mut Self)` + Moves all elements from other into self, leaving other empty. +- `pub fn entry(&mut self, key: S) -> Entry<'_>where S: Into,` + Gets the given key’s corresponding entry in the map for in-place +manipulation. +- `pub fn len(&self) -> usize` + Returns the number of elements in the map. +- `pub fn is_empty(&self) -> bool` + Returns true if the map contains no elements. +- `pub fn iter(&self) -> Iter<'_>` + Gets an iterator over the entries of the map. +- `pub fn iter_mut(&mut self) -> IterMut<'_>` + Gets a mutable iterator over the entries of the map. +- `pub fn keys(&self) -> Keys<'_>` + Gets an iterator over the keys of the map. +- `pub fn values(&self) -> Values<'_>` + Gets an iterator over the values of the map. +- `pub fn values_mut(&mut self) -> ValuesMut<'_>` + Gets an iterator over mutable values of the map. +- `pub fn into_values(self) -> IntoValues` + Gets an iterator over the values of the map. +- `pub fn retain(&mut self, f: F)where F: FnMut(&String, &mut Value) -> bool,` + Retains only the elements specified by the predicate. + In other words, remove all pairs (k, v) such that f(&k, &mut v) returns false . +- `pub fn sort_keys(&mut self)` + Sorts this map’s entries in-place using str ’s usual ordering. + If serde_json’s “preserve_order” feature is not enabled, this method +does no work because all JSON maps are always kept in a sorted state. + If serde_json’s “preserve_order” feature is enabled, this method +destroys the original source order or insertion order of this map in +favor of an alphanumerical order that matches how a BTreeMap with the +same contents would be ordered. This takes O(n log n + c) time where n is the length of the map and c is the capacity. + Other maps nested within the values of this map are not sorted. If you +need the entire data structure to be sorted at all levels, you must also +call map. values_mut ().for_each( Value::sort_all_objects ) . + +## Trait Implementations + +### impl Clone for Map +- `fn clone(&self) -> Self` +- `fn clone_from(&mut self, source: &Self)` + +### impl Debug for Map +- `fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>` + +### impl Default for Map +- `fn default() -> Self` + +### impl<'de> Deserialize<'de> for Map +- `fn deserialize(deserializer: D) -> Resultwhere D: Deserializer<'de>,` + +### impl<'de> Deserializer<'de> for &'de Map +- `type Error = Error` +- `fn deserialize_any(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_enum( self, _name: &'static str, _variants: &'static [&'static str], visitor: V, ) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_ignored_any(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_bool( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_i8( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_i16( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_i32( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_i64( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_i128( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_u8( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_u16( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_u32( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_u64( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_u128( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_f32( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_f64( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_char( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_str( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_string( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_bytes( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_byte_buf( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_option( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_unit( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_unit_struct( self, name: &'static str, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_newtype_struct( self, name: &'static str, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_seq( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_tuple( self, len: usize, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_tuple_struct( self, name: &'static str, len: usize, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_map( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_struct( self, name: &'static str, fields: &'static [&'static str], visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_identifier( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn is_human_readable(&self) -> bool` + +### impl<'de> Deserializer<'de> for Map +- `type Error = Error` +- `fn deserialize_any(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_enum( self, _name: &'static str, _variants: &'static [&'static str], visitor: V, ) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_ignored_any(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_bool( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_i8( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_i16( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_i32( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_i64( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_i128( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_u8( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_u16( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_u32( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_u64( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_u128( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_f32( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_f64( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_char( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_str( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_string( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_bytes( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_byte_buf( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_option( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_unit( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_unit_struct( self, name: &'static str, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_newtype_struct( self, name: &'static str, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_seq( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_tuple( self, len: usize, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_tuple_struct( self, name: &'static str, len: usize, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_map( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_struct( self, name: &'static str, fields: &'static [&'static str], visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn deserialize_identifier( self, visitor: V, ) -> Result>::Error>where V: Visitor<'de>,` +- `fn is_human_readable(&self) -> bool` + +### impl Extend<(String, Value)> for Map +- `fn extend(&mut self, iter: T)where T: IntoIterator,` +- `fn extend_one(&mut self, item: A)` +- `fn extend_reserve(&mut self, additional: usize)` + +### impl From> for Value +- `fn from(f: Map) -> Self` + Convert map (with string keys) to Value::Object . + **Examples** + ``` + use serde_json::{Map, Value}; + + let mut m = Map::new(); + m.insert("Lorem".to_owned(), "ipsum".into()); + let x: Value = m.into(); + ``` + +### impl FromIterator<(String, Value)> for Map +- `fn from_iter(iter: T) -> Selfwhere T: IntoIterator,` + +### impl FromStr for Map +- `type Err = Error` +- `fn from_str(s: &str) -> Result` + +### impl Hash for Map +- `fn hash(&self, state: &mut H)` +- `fn hash_slice(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,` + +### impl Index<&Q> for Mapwhere String: Borrow, Q: ?Sized + Ord + Eq + Hash, + Access an element of this map. Panics if the given key is not present in the +map. + ``` + match val { + Value::String(s) => Some(s.as_str()), + Value::Array(arr) => arr[0].as_str(), + Value::Object(map) => map["type"].as_str(), + _ => None, + } + ``` +- `type Output = Value` +- `fn index(&self, index: &Q) -> &Value` + +### impl IndexMut<&Q> for Mapwhere String: Borrow, Q: ?Sized + Ord + Eq + Hash, + Mutably access an element of this map. Panics if the given key is not +present in the map. + ``` + map["key"] = json!("value"); + ``` +- `fn index_mut(&mut self, index: &Q) -> &mut Value` + +### impl<'de> IntoDeserializer<'de, Error> for &'de Map +- `type Deserializer = &'de Map` +- `fn into_deserializer(self) -> Self::Deserializer` + +### impl<'de> IntoDeserializer<'de, Error> for Map +- `type Deserializer = Map` +- `fn into_deserializer(self) -> Self::Deserializer` + +### impl<'a> IntoIterator for &'a Map +- `type Item = (&'a String, &'a Value)` +- `type IntoIter = Iter<'a>` +- `fn into_iter(self) -> Self::IntoIter` + +### impl<'a> IntoIterator for &'a mut Map +- `type Item = (&'a String, &'a mut Value)` +- `type IntoIter = IterMut<'a>` +- `fn into_iter(self) -> Self::IntoIter` + +### impl IntoIterator for Map +- `type Item = (String, Value)` +- `type IntoIter = IntoIter` +- `fn into_iter(self) -> Self::IntoIter` + +### impl PartialEq for Map +- `fn eq(&self, other: &Self) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl Serialize for Map +- `fn serialize(&self, serializer: S) -> Resultwhere S: Serializer,` + +### impl Eq for Map diff --git a/internal/app/testdata/rustdoc_doc_serdejson_map.html b/internal/app/testdata/rustdoc_doc_serdejson_map.html new file mode 100644 index 0000000..aab0a5d --- /dev/null +++ b/internal/app/testdata/rustdoc_doc_serdejson_map.html @@ -0,0 +1,774 @@ +Map in serde_json - Rust + + + + +
+ + +Skip to main content

Map

Struct Map 

Source
pub struct Map<K, V> { /* private fields */ }
Expand description

Represents a JSON key/value type.

+

Implementations§

Source§

impl Map<String, Value>

Source

pub fn new() -> Self

Makes a new empty Map.

+
Source

pub fn with_capacity(capacity: usize) -> Self

Makes a new empty Map with the given initial capacity.

+
Source

pub fn clear(&mut self)

Clears the map, removing all values.

+
Source

pub fn get<Q>(&self, key: &Q) -> Option<&Value>
where + String: Borrow<Q>, + Q: ?Sized + Ord + Eq + Hash,

Returns a reference to the value corresponding to the key.

+

The key may be any borrowed form of the map’s key type, but the ordering +on the borrowed form must match the ordering on the key type.

+
Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where + String: Borrow<Q>, + Q: ?Sized + Ord + Eq + Hash,

Returns true if the map contains a value for the specified key.

+

The key may be any borrowed form of the map’s key type, but the ordering +on the borrowed form must match the ordering on the key type.

+
Source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut Value>
where + String: Borrow<Q>, + Q: ?Sized + Ord + Eq + Hash,

Returns a mutable reference to the value corresponding to the key.

+

The key may be any borrowed form of the map’s key type, but the ordering +on the borrowed form must match the ordering on the key type.

+
Source

pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>
where + String: Borrow<Q>, + Q: ?Sized + Ord + Eq + Hash,

Returns the key-value pair matching the given key.

+

The key may be any borrowed form of the map’s key type, but the ordering +on the borrowed form must match the ordering on the key type.

+
Source

pub fn insert(&mut self, k: String, v: Value) -> Option<Value>

Inserts a key-value pair into the map.

+

If the map did not have this key present, None is returned.

+

If the map did have this key present, the value is updated, and the old +value is returned.

+
Source

pub fn shift_insert( + &mut self, + index: usize, + k: String, + v: Value, +) -> Option<Value>

Available on crate feature preserve_order only.

Insert a key-value pair in the map at the given index.

+

If the map did not have this key present, None is returned.

+

If the map did have this key present, the key is moved to the new +position, the value is updated, and the old value is returned.

+
Source

pub fn remove<Q>(&mut self, key: &Q) -> Option<Value>
where + String: Borrow<Q>, + Q: ?Sized + Ord + Eq + Hash,

Removes a key from the map, returning the value at the key if the key +was previously in the map.

+

The key may be any borrowed form of the map’s key type, but the ordering +on the borrowed form must match the ordering on the key type.

+

If serde_json’s “preserve_order” is enabled, .remove(key) is +equivalent to .swap_remove(key), replacing this +entry’s position with the last element. If you need to preserve the +relative order of the keys in the map, use +.shift_remove(key) instead.

+
Source

pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>
where + String: Borrow<Q>, + Q: ?Sized + Ord + Eq + Hash,

Removes a key from the map, returning the stored key and value if the +key was previously in the map.

+

The key may be any borrowed form of the map’s key type, but the ordering +on the borrowed form must match the ordering on the key type.

+

If serde_json’s “preserve_order” is enabled, .remove_entry(key) is +equivalent to .swap_remove_entry(key), +replacing this entry’s position with the last element. If you need to +preserve the relative order of the keys in the map, use +.shift_remove_entry(key) instead.

+
Source

pub fn swap_remove<Q>(&mut self, key: &Q) -> Option<Value>
where + String: Borrow<Q>, + Q: ?Sized + Ord + Eq + Hash,

Available on crate feature preserve_order only.

Removes and returns the value corresponding to the key from the map.

+

Like Vec::swap_remove, the entry is removed by swapping it with the +last element of the map and popping it off. This perturbs the position +of what used to be the last element!

+
Source

pub fn swap_remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>
where + String: Borrow<Q>, + Q: ?Sized + Ord + Eq + Hash,

Available on crate feature preserve_order only.

Remove and return the key-value pair.

+

Like Vec::swap_remove, the entry is removed by swapping it with the +last element of the map and popping it off. This perturbs the position +of what used to be the last element!

+
Source

pub fn shift_remove<Q>(&mut self, key: &Q) -> Option<Value>
where + String: Borrow<Q>, + Q: ?Sized + Ord + Eq + Hash,

Available on crate feature preserve_order only.

Removes and returns the value corresponding to the key from the map.

+

Like Vec::remove, the entry is removed by shifting all of the +elements that follow it, preserving their relative order. This perturbs +the index of all of those elements!

+
Source

pub fn shift_remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>
where + String: Borrow<Q>, + Q: ?Sized + Ord + Eq + Hash,

Available on crate feature preserve_order only.

Remove and return the key-value pair.

+

Like Vec::remove, the entry is removed by shifting all of the +elements that follow it, preserving their relative order. This perturbs +the index of all of those elements!

+
Source

pub fn append(&mut self, other: &mut Self)

Moves all elements from other into self, leaving other empty.

+
Source

pub fn entry<S>(&mut self, key: S) -> Entry<'_>
where + S: Into<String>,

Gets the given key’s corresponding entry in the map for in-place +manipulation.

+
Source

pub fn len(&self) -> usize

Returns the number of elements in the map.

+
Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

+
Source

pub fn iter(&self) -> Iter<'_> ⓘ

Gets an iterator over the entries of the map.

+
Source

pub fn iter_mut(&mut self) -> IterMut<'_> ⓘ

Gets a mutable iterator over the entries of the map.

+
Source

pub fn keys(&self) -> Keys<'_> ⓘ

Gets an iterator over the keys of the map.

+
Source

pub fn values(&self) -> Values<'_> ⓘ

Gets an iterator over the values of the map.

+
Source

pub fn values_mut(&mut self) -> ValuesMut<'_> ⓘ

Gets an iterator over mutable values of the map.

+
Source

pub fn into_values(self) -> IntoValues ⓘ

Gets an iterator over the values of the map.

+
Source

pub fn retain<F>(&mut self, f: F)
where + F: FnMut(&String, &mut Value) -> bool,

Retains only the elements specified by the predicate.

+

In other words, remove all pairs (k, v) such that f(&k, &mut v) +returns false.

+
Source

pub fn sort_keys(&mut self)

Sorts this map’s entries in-place using str’s usual ordering.

+

If serde_json’s “preserve_order” feature is not enabled, this method +does no work because all JSON maps are always kept in a sorted state.

+

If serde_json’s “preserve_order” feature is enabled, this method +destroys the original source order or insertion order of this map in +favor of an alphanumerical order that matches how a BTreeMap with the +same contents would be ordered. This takes O(n log n + c) time where +n is the length of the map and c is the capacity.

+

Other maps nested within the values of this map are not sorted. If you +need the entire data structure to be sorted at all levels, you must also +call +map.values_mut().for_each(Value::sort_all_objects).

+

Trait Implementations§

Source§

impl Clone for Map<String, Value>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Map<String, Value>

Source§

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

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

impl Default for Map<String, Value>

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Map<String, Value>

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<'de> Deserializer<'de> for &'de Map<String, Value>

Source§

type Error = Error

The error type that can be returned if some error occurs during +deserialization.
Source§

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where + V: Visitor<'de>,

Require the Deserializer to figure out how to drive the visitor based +on what data type is in the input. Read more
Source§

fn deserialize_enum<V>( + self, + _name: &'static str, + _variants: &'static [&'static str], + visitor: V, +) -> Result<V::Value, Self::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an enum value with a +particular name and possible variants.
Source§

fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type needs to deserialize a value whose type +doesn’t matter because it is ignored. Read more
Source§

fn deserialize_bool<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a bool value.
Source§

fn deserialize_i8<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i8 value.
Source§

fn deserialize_i16<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i16 value.
Source§

fn deserialize_i32<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i32 value.
Source§

fn deserialize_i64<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i64 value.
Source§

fn deserialize_i128<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i128 value. Read more
Source§

fn deserialize_u8<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a u8 value.
Source§

fn deserialize_u16<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a u16 value.
Source§

fn deserialize_u32<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a u32 value.
Source§

fn deserialize_u64<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a u64 value.
Source§

fn deserialize_u128<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an u128 value. Read more
Source§

fn deserialize_f32<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a f32 value.
Source§

fn deserialize_f64<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a f64 value.
Source§

fn deserialize_char<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a char value.
Source§

fn deserialize_str<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a string value and does +not benefit from taking ownership of buffered data owned by the +Deserializer. Read more
Source§

fn deserialize_string<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a string value and would +benefit from taking ownership of buffered data owned by the +Deserializer. Read more
Source§

fn deserialize_bytes<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a byte array and does not +benefit from taking ownership of buffered data owned by the +Deserializer. Read more
Source§

fn deserialize_byte_buf<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a byte array and would +benefit from taking ownership of buffered data owned by the +Deserializer. Read more
Source§

fn deserialize_option<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an optional value. Read more
Source§

fn deserialize_unit<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit value.
Source§

fn deserialize_unit_struct<V>( + self, + name: &'static str, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit struct with a +particular name.
Source§

fn deserialize_newtype_struct<V>( + self, + name: &'static str, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a newtype struct with a +particular name.
Source§

fn deserialize_seq<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values.
Source§

fn deserialize_tuple<V>( + self, + len: usize, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values and +knows how many values there are without looking at the serialized data.
Source§

fn deserialize_tuple_struct<V>( + self, + name: &'static str, + len: usize, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a tuple struct with a +particular name and number of fields.
Source§

fn deserialize_map<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a map of key-value pairs.
Source§

fn deserialize_struct<V>( + self, + name: &'static str, + fields: &'static [&'static str], + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a struct with a particular +name and fields.
Source§

fn deserialize_identifier<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting the name of a struct +field or the discriminant of an enum variant.
Source§

fn is_human_readable(&self) -> bool

Determine whether Deserialize implementations should expect to +deserialize their human-readable form. Read more
Source§

impl<'de> Deserializer<'de> for Map<String, Value>

Source§

type Error = Error

The error type that can be returned if some error occurs during +deserialization.
Source§

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where + V: Visitor<'de>,

Require the Deserializer to figure out how to drive the visitor based +on what data type is in the input. Read more
Source§

fn deserialize_enum<V>( + self, + _name: &'static str, + _variants: &'static [&'static str], + visitor: V, +) -> Result<V::Value, Self::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an enum value with a +particular name and possible variants.
Source§

fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type needs to deserialize a value whose type +doesn’t matter because it is ignored. Read more
Source§

fn deserialize_bool<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a bool value.
Source§

fn deserialize_i8<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i8 value.
Source§

fn deserialize_i16<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i16 value.
Source§

fn deserialize_i32<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i32 value.
Source§

fn deserialize_i64<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i64 value.
Source§

fn deserialize_i128<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i128 value. Read more
Source§

fn deserialize_u8<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a u8 value.
Source§

fn deserialize_u16<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a u16 value.
Source§

fn deserialize_u32<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a u32 value.
Source§

fn deserialize_u64<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a u64 value.
Source§

fn deserialize_u128<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an u128 value. Read more
Source§

fn deserialize_f32<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a f32 value.
Source§

fn deserialize_f64<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a f64 value.
Source§

fn deserialize_char<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a char value.
Source§

fn deserialize_str<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a string value and does +not benefit from taking ownership of buffered data owned by the +Deserializer. Read more
Source§

fn deserialize_string<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a string value and would +benefit from taking ownership of buffered data owned by the +Deserializer. Read more
Source§

fn deserialize_bytes<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a byte array and does not +benefit from taking ownership of buffered data owned by the +Deserializer. Read more
Source§

fn deserialize_byte_buf<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a byte array and would +benefit from taking ownership of buffered data owned by the +Deserializer. Read more
Source§

fn deserialize_option<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an optional value. Read more
Source§

fn deserialize_unit<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit value.
Source§

fn deserialize_unit_struct<V>( + self, + name: &'static str, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit struct with a +particular name.
Source§

fn deserialize_newtype_struct<V>( + self, + name: &'static str, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a newtype struct with a +particular name.
Source§

fn deserialize_seq<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values.
Source§

fn deserialize_tuple<V>( + self, + len: usize, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values and +knows how many values there are without looking at the serialized data.
Source§

fn deserialize_tuple_struct<V>( + self, + name: &'static str, + len: usize, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a tuple struct with a +particular name and number of fields.
Source§

fn deserialize_map<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a map of key-value pairs.
Source§

fn deserialize_struct<V>( + self, + name: &'static str, + fields: &'static [&'static str], + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a struct with a particular +name and fields.
Source§

fn deserialize_identifier<V>( + self, + visitor: V, +) -> Result<V::Value, <Self as Deserializer<'de>>::Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting the name of a struct +field or the discriminant of an enum variant.
Source§

fn is_human_readable(&self) -> bool

Determine whether Deserialize implementations should expect to +deserialize their human-readable form. Read more
Source§

impl Extend<(String, Value)> for Map<String, Value>

Source§

fn extend<T>(&mut self, iter: T)
where + T: IntoIterator<Item = (String, Value)>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<Map<String, Value>> for Value

Source§

fn from(f: Map<String, Value>) -> Self

Convert map (with string keys) to Value::Object.

+
§Examples
+
use serde_json::{Map, Value};
+
+let mut m = Map::new();
+m.insert("Lorem".to_owned(), "ipsum".into());
+let x: Value = m.into();
Source§

impl FromIterator<(String, Value)> for Map<String, Value>

Source§

fn from_iter<T>(iter: T) -> Self
where + T: IntoIterator<Item = (String, Value)>,

Creates a value from an iterator. Read more
Source§

impl FromStr for Map<String, Value>

Source§

type Err = Error

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

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

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

impl Hash for Map<String, Value>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where + H: Hasher, + Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<Q> Index<&Q> for Map<String, Value>
where + String: Borrow<Q>, + Q: ?Sized + Ord + Eq + Hash,

Access an element of this map. Panics if the given key is not present in the +map.

+
+
match val {
+    Value::String(s) => Some(s.as_str()),
+    Value::Array(arr) => arr[0].as_str(),
+    Value::Object(map) => map["type"].as_str(),
+    _ => None,
+}
Source§

type Output = Value

The returned type after indexing.
Source§

fn index(&self, index: &Q) -> &Value

Performs the indexing (container[index]) operation. Read more
Source§

impl<Q> IndexMut<&Q> for Map<String, Value>
where + String: Borrow<Q>, + Q: ?Sized + Ord + Eq + Hash,

Mutably access an element of this map. Panics if the given key is not +present in the map.

+
+
map["key"] = json!("value");
Source§

fn index_mut(&mut self, index: &Q) -> &mut Value

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'de> IntoDeserializer<'de, Error> for &'de Map<String, Value>

Source§

type Deserializer = &'de Map<String, Value>

The type of the deserializer being converted into.
Source§

fn into_deserializer(self) -> Self::Deserializer

Convert this value into a deserializer.
Source§

impl<'de> IntoDeserializer<'de, Error> for Map<String, Value>

Source§

type Deserializer = Map<String, Value>

The type of the deserializer being converted into.
Source§

fn into_deserializer(self) -> Self::Deserializer

Convert this value into a deserializer.
Source§

impl<'a> IntoIterator for &'a Map<String, Value>

Source§

type Item = (&'a String, &'a Value)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a mut Map<String, Value>

Source§

type Item = (&'a String, &'a mut Value)

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Map<String, Value>

Source§

type Item = (String, Value)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Map<String, Value>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Serialize for Map<String, Value>

Available on crate features std or alloc only.
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 Eq for Map<String, Value>

Auto Trait Implementations§

§

impl<K, V> Freeze for Map<K, V>

§

impl<K, V> RefUnwindSafe for Map<K, V>
where + K: RefUnwindSafe, + V: RefUnwindSafe,

§

impl<K, V> Send for Map<K, V>
where + K: Send, + V: Send,

§

impl<K, V> Sync for Map<K, V>
where + K: Sync, + V: Sync,

§

impl<K, V> Unpin for Map<K, V>
where + K: Unpin, + V: Unpin,

§

impl<K, V> UnsafeUnpin for Map<K, V>

§

impl<K, V> UnwindSafe for Map<K, V>
where + K: UnwindSafe, + V: UnwindSafe,

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> 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, 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, 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> DeserializeOwned for T
where + T: for<'de> Deserialize<'de>,

\ No newline at end of file diff --git a/internal/app/testdata/rustdoc_doc_serdejson_tostring.golden b/internal/app/testdata/rustdoc_doc_serdejson_tostring.golden new file mode 100644 index 0000000..cfbccd7 --- /dev/null +++ b/internal/app/testdata/rustdoc_doc_serdejson_tostring.golden @@ -0,0 +1,10 @@ +# Function to_ string +```rust +pub fn to_string(value: &T) -> Resultwhere + T: ?Sized + Serialize, +``` +Serialize the given data structure as a String of JSON. + +## Errors +Serialization can fail if T ’s implementation of Serialize decides to +fail, or if T contains a map with non-string keys. diff --git a/internal/app/testdata/rustdoc_doc_serdejson_tostring.html b/internal/app/testdata/rustdoc_doc_serdejson_tostring.html new file mode 100644 index 0000000..20ff592 --- /dev/null +++ b/internal/app/testdata/rustdoc_doc_serdejson_tostring.html @@ -0,0 +1,325 @@ +to_string in serde_json - Rust + + + + +
+ + +Skip to main content

to_string

Function to_string 

Source
pub fn to_string<T>(value: &T) -> Result<String>
where + T: ?Sized + Serialize,
Available on crate feature std only.
Expand description

Serialize the given data structure as a String of JSON.

+

§Errors

+

Serialization can fail if T’s implementation of Serialize decides to +fail, or if T contains a map with non-string keys.

+
\ No newline at end of file diff --git a/internal/app/testdata/rustdoc_doc_serdejson_value.golden b/internal/app/testdata/rustdoc_doc_serdejson_value.golden new file mode 100644 index 0000000..09882e4 --- /dev/null +++ b/internal/app/testdata/rustdoc_doc_serdejson_value.golden @@ -0,0 +1,1054 @@ +# Enum Value +```rust +pub enum Value { + Null, + Bool(bool), + Number(Number), + String(String), + Array(Vec), + Object(Map), +} +``` +Represents any valid JSON value. +See the serde_json::value module documentation for usage examples. + +## Variants +- `Null` + Represents a JSON null value. + ``` + let v = json!(null); + ``` +- `Bool(bool)` + Represents a JSON boolean. + ``` + let v = json!(true); + ``` +- `Number(Number)` + Represents a JSON number, whether integer or floating point. + ``` + let v = json!(12.5); + ``` +- `String(String)` + Represents a JSON string. + ``` + let v = json!("a string"); + ``` +- `Array(Vec)` + Represents a JSON array. + ``` + let v = json!(["an", "array"]); + ``` +- `Object(Map)` + Represents a JSON object. + By default the map is backed by a BTreeMap. Enable the preserve_order feature of serde_json to use IndexMap instead, which preserves +entries in the order they are inserted into the map. In particular, this +allows JSON data to be deserialized into a Value and serialized to a +string while retaining the order of map keys in the input. + ``` + let v = json!({ "an": "object" }); + ``` + +## Implementations + +### impl Value +- `pub fn get(&self, index: I) -> Option<&Value>` + Index into a JSON array or map. A string index can be used to access a +value in a map, and a usize index can be used to access an element of an +array. + Returns None if the type of self does not match the type of the +index, for example if the index is a string and self is an array or a +number. Also returns None if the given key does not exist in the map +or the given index is not within the bounds of the array. + ``` + let object = json!({ "A": 65, "B": 66, "C": 67 }); + assert_eq!(*object.get("A").unwrap(), json!(65)); + + let array = json!([ "A", "B", "C" ]); + assert_eq!(*array.get(2).unwrap(), json!("C")); + + assert_eq!(array.get("A"), None); + ``` + Square brackets can also be used to index into a value in a more concise +way. This returns Value::Null in cases where get would have returned None . + ``` + let object = json!({ + "A": ["a", "á", "à"], + "B": ["b", "b́"], + "C": ["c", "ć", "ć̣", "ḉ"], + }); + assert_eq!(object["B"][0], json!("b")); + + assert_eq!(object["D"], json!(null)); + assert_eq!(object[0]["x"]["y"]["z"], json!(null)); + ``` +- `pub fn get_mut(&mut self, index: I) -> Option<&mut Value>` + Mutably index into a JSON array or map. A string index can be used to +access a value in a map, and a usize index can be used to access an +element of an array. + Returns None if the type of self does not match the type of the +index, for example if the index is a string and self is an array or a +number. Also returns None if the given key does not exist in the map +or the given index is not within the bounds of the array. + ``` + let mut object = json!({ "A": 65, "B": 66, "C": 67 }); + *object.get_mut("A").unwrap() = json!(69); + + let mut array = json!([ "A", "B", "C" ]); + *array.get_mut(2).unwrap() = json!("D"); + ``` +- `pub fn is_object(&self) -> bool` + Returns true if the Value is an Object. Returns false otherwise. + For any Value on which is_object returns true, as_object and as_object_mut are guaranteed to return the map representation of the +object. + ``` + let obj = json!({ "a": { "nested": true }, "b": ["an", "array"] }); + + assert!(obj.is_object()); + assert!(obj["a"].is_object()); + + // array, not an object + assert!(!obj["b"].is_object()); + ``` +- `pub fn as_object(&self) -> Option<&Map>` + If the Value is an Object, returns the associated Map. Returns None +otherwise. + ``` + let v = json!({ "a": { "nested": true }, "b": ["an", "array"] }); + + // The length of `{"nested": true}` is 1 entry. + assert_eq!(v["a"].as_object().unwrap().len(), 1); + + // The array `["an", "array"]` is not an object. + assert_eq!(v["b"].as_object(), None); + ``` +- `pub fn as_object_mut(&mut self) -> Option<&mut Map>` + If the Value is an Object, returns the associated mutable Map. +Returns None otherwise. + ``` + let mut v = json!({ "a": { "nested": true } }); + + v["a"].as_object_mut().unwrap().clear(); + assert_eq!(v, json!({ "a": {} })); + ``` +- `pub fn is_array(&self) -> bool` + Returns true if the Value is an Array. Returns false otherwise. + For any Value on which is_array returns true, as_array and as_array_mut are guaranteed to return the vector representing the +array. + ``` + let obj = json!({ "a": ["an", "array"], "b": { "an": "object" } }); + + assert!(obj["a"].is_array()); + + // an object, not an array + assert!(!obj["b"].is_array()); + ``` +- `pub fn as_array(&self) -> Option<&Vec>` + If the Value is an Array, returns the associated vector. Returns None +otherwise. + ``` + let v = json!({ "a": ["an", "array"], "b": { "an": "object" } }); + + // The length of `["an", "array"]` is 2 elements. + assert_eq!(v["a"].as_array().unwrap().len(), 2); + + // The object `{"an": "object"}` is not an array. + assert_eq!(v["b"].as_array(), None); + ``` +- `pub fn as_array_mut(&mut self) -> Option<&mut Vec>` + If the Value is an Array, returns the associated mutable vector. +Returns None otherwise. + ``` + let mut v = json!({ "a": ["an", "array"] }); + + v["a"].as_array_mut().unwrap().clear(); + assert_eq!(v, json!({ "a": [] })); + ``` +- `pub fn is_string(&self) -> bool` + Returns true if the Value is a String. Returns false otherwise. + For any Value on which is_string returns true, as_str is guaranteed +to return the string slice. + ``` + let v = json!({ "a": "some string", "b": false }); + + assert!(v["a"].is_string()); + + // The boolean `false` is not a string. + assert!(!v["b"].is_string()); + ``` +- `pub fn as_str(&self) -> Option<&str>` + If the Value is a String, returns the associated str. Returns None +otherwise. + ``` + let v = json!({ "a": "some string", "b": false }); + + assert_eq!(v["a"].as_str(), Some("some string")); + + // The boolean `false` is not a string. + assert_eq!(v["b"].as_str(), None); + + // JSON values are printed in JSON representation, so strings are in quotes. + // + // The value is: "some string" + println!("The value is: {}", v["a"]); + + // Rust strings are printed without quotes. + // + // The value is: some string + println!("The value is: {}", v["a"].as_str().unwrap()); + ``` +- `pub fn is_number(&self) -> bool` + Returns true if the Value is a Number. Returns false otherwise. + ``` + let v = json!({ "a": 1, "b": "2" }); + + assert!(v["a"].is_number()); + + // The string `"2"` is a string, not a number. + assert!(!v["b"].is_number()); + ``` +- `pub fn as_number(&self) -> Option<&Number>` + If the Value is a Number, returns the associated Number . Returns +None otherwise. + ``` + let v = json!({ "a": 1, "b": 2.2, "c": -3, "d": "4" }); + + assert_eq!(v["a"].as_number(), Some(&Number::from(1u64))); + assert_eq!(v["b"].as_number(), Some(&Number::from_f64(2.2).unwrap())); + assert_eq!(v["c"].as_number(), Some(&Number::from(-3i64))); + + // The string `"4"` is not a number. + assert_eq!(v["d"].as_number(), None); + ``` +- `pub fn is_i64(&self) -> bool` + Returns true if the Value is an integer between i64::MIN and i64::MAX . + For any Value on which is_i64 returns true, as_i64 is guaranteed to +return the integer value. + ``` + let big = i64::max_value() as u64 + 10; + let v = json!({ "a": 64, "b": big, "c": 256.0 }); + + assert!(v["a"].is_i64()); + + // Greater than i64::MAX. + assert!(!v["b"].is_i64()); + + // Numbers with a decimal point are not considered integers. + assert!(!v["c"].is_i64()); + ``` +- `pub fn is_u64(&self) -> bool` + Returns true if the Value is an integer between zero and u64::MAX . + For any Value on which is_u64 returns true, as_u64 is guaranteed to +return the integer value. + ``` + let v = json!({ "a": 64, "b": -64, "c": 256.0 }); + + assert!(v["a"].is_u64()); + + // Negative integer. + assert!(!v["b"].is_u64()); + + // Numbers with a decimal point are not considered integers. + assert!(!v["c"].is_u64()); + ``` +- `pub fn is_f64(&self) -> bool` + Returns true if the Value is a number that can be represented by f64. + For any Value on which is_f64 returns true, as_f64 is guaranteed to +return the floating point value. + Currently this function returns true if and only if both is_i64 and is_u64 return false but this is not a guarantee in the future. + ``` + let v = json!({ "a": 256.0, "b": 64, "c": -64 }); + + assert!(v["a"].is_f64()); + + // Integers. + assert!(!v["b"].is_f64()); + assert!(!v["c"].is_f64()); + ``` +- `pub fn as_i64(&self) -> Option` + If the Value is an integer, represent it as i64 if possible. Returns +None otherwise. + ``` + let big = i64::max_value() as u64 + 10; + let v = json!({ "a": 64, "b": big, "c": 256.0 }); + + assert_eq!(v["a"].as_i64(), Some(64)); + assert_eq!(v["b"].as_i64(), None); + assert_eq!(v["c"].as_i64(), None); + ``` +- `pub fn as_u64(&self) -> Option` + If the Value is an integer, represent it as u64 if possible. Returns +None otherwise. + ``` + let v = json!({ "a": 64, "b": -64, "c": 256.0 }); + + assert_eq!(v["a"].as_u64(), Some(64)); + assert_eq!(v["b"].as_u64(), None); + assert_eq!(v["c"].as_u64(), None); + ``` +- `pub fn as_f64(&self) -> Option` + If the Value is a number, represent it as f64 if possible. Returns +None otherwise. + ``` + let v = json!({ "a": 256.0, "b": 64, "c": -64 }); + + assert_eq!(v["a"].as_f64(), Some(256.0)); + assert_eq!(v["b"].as_f64(), Some(64.0)); + assert_eq!(v["c"].as_f64(), Some(-64.0)); + ``` +- `pub fn is_boolean(&self) -> bool` + Returns true if the Value is a Boolean. Returns false otherwise. + For any Value on which is_boolean returns true, as_bool is +guaranteed to return the boolean value. + ``` + let v = json!({ "a": false, "b": "false" }); + + assert!(v["a"].is_boolean()); + + // The string `"false"` is a string, not a boolean. + assert!(!v["b"].is_boolean()); + ``` +- `pub fn as_bool(&self) -> Option` + If the Value is a Boolean, returns the associated bool. Returns None +otherwise. + ``` + let v = json!({ "a": false, "b": "false" }); + + assert_eq!(v["a"].as_bool(), Some(false)); + + // The string `"false"` is a string, not a boolean. + assert_eq!(v["b"].as_bool(), None); + ``` +- `pub fn is_null(&self) -> bool` + Returns true if the Value is a Null. Returns false otherwise. + For any Value on which is_null returns true, as_null is guaranteed +to return Some(()) . + ``` + let v = json!({ "a": null, "b": false }); + + assert!(v["a"].is_null()); + + // The boolean `false` is not null. + assert!(!v["b"].is_null()); + ``` +- `pub fn as_null(&self) -> Option<()>` + If the Value is a Null, returns (). Returns None otherwise. + ``` + let v = json!({ "a": null, "b": false }); + + assert_eq!(v["a"].as_null(), Some(())); + + // The boolean `false` is not null. + assert_eq!(v["b"].as_null(), None); + ``` +- `pub fn pointer(&self, pointer: &str) -> Option<&Value>` + Looks up a value by a JSON Pointer. + JSON Pointer defines a string syntax for identifying a specific value +within a JavaScript Object Notation (JSON) document. + A Pointer is a Unicode string with the reference tokens separated by / . +Inside tokens / is replaced by ~1 and ~ is replaced by ~0 . The +addressed value is returned and if there is no such value None is +returned. + For more information read RFC6901 . + **Examples** + ``` + let data = json!({ + "x": { + "y": ["z", "zz"] + } + }); + + assert_eq!(data.pointer("/x/y/1").unwrap(), &json!("zz")); + assert_eq!(data.pointer("/a/b/c"), None); + ``` +- `pub fn pointer_mut(&mut self, pointer: &str) -> Option<&mut Value>` + Looks up a value by a JSON Pointer and returns a mutable reference to +that value. + JSON Pointer defines a string syntax for identifying a specific value +within a JavaScript Object Notation (JSON) document. + A Pointer is a Unicode string with the reference tokens separated by / . +Inside tokens / is replaced by ~1 and ~ is replaced by ~0 . The +addressed value is returned and if there is no such value None is +returned. + For more information read RFC6901 . + **Example of Use** + ``` + use serde_json::Value; + + fn main() { + let s = r#"{"x": 1.0, "y": 2.0}"#; + let mut value: Value = serde_json::from_str(s).unwrap(); + + // Check value using read-only pointer + assert_eq!(value.pointer("/x"), Some(&1.0.into())); + // Change value with direct assignment + *value.pointer_mut("/x").unwrap() = 1.5.into(); + // Check that new value was written + assert_eq!(value.pointer("/x"), Some(&1.5.into())); + // Or change the value only if it exists + value.pointer_mut("/x").map(|v| *v = 1.5.into()); + + // "Steal" ownership of a value. Can replace with any valid Value. + let old_x = value.pointer_mut("/x").map(Value::take).unwrap(); + assert_eq!(old_x, 1.5); + assert_eq!(value.pointer("/x").unwrap(), &Value::Null); + } + ``` +- `pub fn take(&mut self) -> Value` + Takes the value out of the Value , leaving a Null in its place. + ``` + let mut v = json!({ "x": "y" }); + assert_eq!(v["x"].take(), json!("y")); + assert_eq!(v, json!({ "x": null })); + ``` +- `pub fn sort_all_objects(&mut self)` + Reorders the entries of all Value::Object nested within this JSON +value according to str ’s usual ordering. + If serde_json’s “preserve_order” feature is not enabled, this method +does no work because all JSON maps are always kept in a sorted state. + If serde_json’s “preserve_order” feature is enabled, this method +destroys the original source order or insertion order of the JSON +objects in favor of an alphanumerical order that matches how a BTreeMap +with the same contents would be ordered. + +## Trait Implementations + +### impl Clone for Value +- `fn clone(&self) -> Value` +- `fn clone_from(&mut self, source: &Self)` + +### impl Debug for Value +- `fn fmt(&self, formatter: &mut Formatter<'_>) -> Result` + +### impl Default for &Value +- `fn default() -> Self` + +### impl Default for Value + The default value is Value::Null . + This is useful for handling omitted Value fields when deserializing. + **Examples** + ``` + use serde_json::Value; + + #[derive(Deserialize)] + struct Settings { + level: i32, + #[serde(default)] + extras: Value, + } + + let data = r#" { "level": 42 } "#; + let s: Settings = serde_json::from_str(data)?; + + assert_eq!(s.level, 42); + assert_eq!(s.extras, Value::Null); + ``` +- `fn default() -> Value` + +### impl<'de> Deserialize<'de> for Value +- `fn deserialize(deserializer: D) -> Resultwhere D: Deserializer<'de>,` + +### impl<'de> Deserializer<'de> for &'de Value +- `type Error = Error` +- `fn deserialize_any(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_i8(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_i16(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_i32(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_i64(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_i128(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_u8(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_u16(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_u32(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_u64(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_u128(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_f32(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_f64(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_option(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_enum( self, name: &'static str, variants: &'static [&'static str], visitor: V, ) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_newtype_struct( self, name: &'static str, visitor: V, ) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_bool(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_char(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_str(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_string(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_bytes(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_byte_buf(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_unit(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_unit_struct( self, _name: &'static str, visitor: V, ) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_seq(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_tuple( self, _len: usize, visitor: V, ) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_tuple_struct( self, _name: &'static str, _len: usize, visitor: V, ) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_map(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_struct( self, _name: &'static str, _fields: &'static [&'static str], visitor: V, ) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_identifier(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_ignored_any(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn is_human_readable(&self) -> bool` + +### impl<'de> Deserializer<'de> for Value +- `type Error = Error` +- `fn deserialize_any(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_i8(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_i16(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_i32(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_i64(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_i128(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_u8(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_u16(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_u32(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_u64(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_u128(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_f32(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_f64(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_option(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_enum( self, name: &'static str, variants: &'static [&'static str], visitor: V, ) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_newtype_struct( self, name: &'static str, visitor: V, ) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_bool(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_char(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_str(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_string(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_bytes(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_byte_buf(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_unit(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_unit_struct( self, _name: &'static str, visitor: V, ) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_seq(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_tuple( self, _len: usize, visitor: V, ) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_tuple_struct( self, _name: &'static str, _len: usize, visitor: V, ) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_map(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_struct( self, _name: &'static str, _fields: &'static [&'static str], visitor: V, ) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_identifier(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn deserialize_ignored_any(self, visitor: V) -> Resultwhere V: Visitor<'de>,` +- `fn is_human_readable(&self) -> bool` + +### impl Display for Value +- `fn fmt(&self, f: &mut Formatter<'_>) -> Result` + Display a JSON value as a string. + ``` + let json = json!({ "city": "London", "street": "10 Downing Street" }); + + // Compact format: + // + // {"city":"London","street":"10 Downing Street"} + let compact = format!("{}", json); + assert_eq!(compact, + "{\"city\":\"London\",\"street\":\"10 Downing Street\"}"); + + // Pretty format: + // + // { + // "city": "London", + // "street": "10 Downing Street" + // } + let pretty = format!("{:#}", json); + assert_eq!(pretty, + "{\n \"city\": \"London\",\n \"street\": \"10 Downing Street\"\n}"); + ``` + +### impl> From<&[T]> for Value +- `fn from(f: &[T]) -> Self` + Convert a slice to Value::Array . + **Examples** + ``` + use serde_json::Value; + + let v: &[&str] = &["lorem", "ipsum", "dolor"]; + let x: Value = v.into(); + ``` + +### impl From<&str> for Value +- `fn from(f: &str) -> Self` + Convert string slice to Value::String . + **Examples** + ``` + use serde_json::Value; + + let s: &str = "lorem"; + let x: Value = s.into(); + ``` + +### impl, const N: usize> From<[T; N]> for Value +- `fn from(array: [T; N]) -> Self` + +### impl From<()> for Value +- `fn from((): ()) -> Self` + Convert () to Value::Null . + **Examples** + ``` + use serde_json::Value; + + let u = (); + let x: Value = u.into(); + ``` + +### impl<'a> From> for Value +- `fn from(f: Cow<'a, str>) -> Self` + Convert copy-on-write string to Value::String . + **Examples** + ``` + use serde_json::Value; + use std::borrow::Cow; + + let s: Cow = Cow::Borrowed("lorem"); + let x: Value = s.into(); + ``` + ``` + use serde_json::Value; + use std::borrow::Cow; + + let s: Cow = Cow::Owned("lorem".to_owned()); + let x: Value = s.into(); + ``` + +### impl From> for Value +- `fn from(f: Map) -> Self` + Convert map (with string keys) to Value::Object . + **Examples** + ``` + use serde_json::{Map, Value}; + + let mut m = Map::new(); + m.insert("Lorem".to_owned(), "ipsum".into()); + let x: Value = m.into(); + ``` + +### impl From for Value +- `fn from(f: Number) -> Self` + Convert Number to Value::Number . + **Examples** + ``` + use serde_json::{Number, Value}; + + let n = Number::from(7); + let x: Value = n.into(); + ``` + +### impl From> for Valuewhere T: Into, +- `fn from(opt: Option) -> Self` + +### impl From for Value +- `fn from(f: String) -> Self` + Convert String to Value::String . + **Examples** + ``` + use serde_json::Value; + + let s: String = "lorem".to_owned(); + let x: Value = s.into(); + ``` + +### impl> From> for Value +- `fn from(f: Vec) -> Self` + Convert a Vec to Value::Array . + **Examples** + ``` + use serde_json::Value; + + let v = vec!["lorem", "ipsum", "dolor"]; + let x: Value = v.into(); + ``` + +### impl From for Value +- `fn from(f: bool) -> Self` + Convert boolean to Value::Bool . + **Examples** + ``` + use serde_json::Value; + + let b = false; + let x: Value = b.into(); + ``` + +### impl From for Value +- `fn from(f: f32) -> Self` + Convert 32-bit floating point number to Value::Number , or Value::Null if infinite or NaN. + **Examples** + ``` + use serde_json::Value; + + let f: f32 = 13.37; + let x: Value = f.into(); + ``` + +### impl From for Value +- `fn from(f: f64) -> Self` + Convert 64-bit floating point number to Value::Number , or Value::Null if infinite or NaN. + **Examples** + ``` + use serde_json::Value; + + let f: f64 = 13.37; + let x: Value = f.into(); + ``` + +### impl From for Value +- `fn from(n: i16) -> Self` + +### impl From for Value +- `fn from(n: i32) -> Self` + +### impl From for Value +- `fn from(n: i64) -> Self` + +### impl From for Value +- `fn from(n: i8) -> Self` + +### impl From for Value +- `fn from(n: isize) -> Self` + +### impl From for Value +- `fn from(n: u16) -> Self` + +### impl From for Value +- `fn from(n: u32) -> Self` + +### impl From for Value +- `fn from(n: u64) -> Self` + +### impl From for Value +- `fn from(n: u8) -> Self` + +### impl From for Value +- `fn from(n: usize) -> Self` + +### impl, V: Into> FromIterator<(K, V)> for Value +- `fn from_iter>(iter: I) -> Self` + Create a Value::Object by collecting an iterator of key-value pairs. + **Examples** + ``` + use serde_json::Value; + + let v: Vec<_> = vec![("lorem", 40), ("ipsum", 2)]; + let x: Value = v.into_iter().collect(); + ``` + +### impl> FromIterator for Value +- `fn from_iter>(iter: I) -> Self` + Create a Value::Array by collecting an iterator of array elements. + **Examples** + ``` + use serde_json::Value; + + let v = std::iter::repeat(42).take(5); + let x: Value = v.collect(); + ``` + ``` + use serde_json::Value; + + let v: Vec<_> = vec!["lorem", "ipsum", "dolor"]; + let x: Value = v.into_iter().collect(); + ``` + ``` + use std::iter::FromIterator; + use serde_json::Value; + + let x: Value = Value::from_iter(vec!["lorem", "ipsum", "dolor"]); + ``` + +### impl FromStr for Value +- `type Err = Error` +- `fn from_str(s: &str) -> Result` + +### impl Hash for Value +- `fn hash<__H: Hasher>(&self, state: &mut __H)` +- `fn hash_slice(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,` + +### impl Index for Valuewhere I: Index, +- `fn index(&self, index: I) -> &Value` + Index into a serde_json::Value using the syntax value[0] or value["k"] . + Returns Value::Null if the type of self does not match the type of +the index, for example if the index is a string and self is an array +or a number. Also returns Value::Null if the given key does not exist +in the map or the given index is not within the bounds of the array. + For retrieving deeply nested values, you should have a look at the Value::pointer method. + **Examples** + ``` + let data = json!({ + "x": { + "y": ["z", "zz"] + } + }); + + assert_eq!(data["x"]["y"], json!(["z", "zz"])); + assert_eq!(data["x"]["y"][0], json!("z")); + + assert_eq!(data["a"], json!(null)); // returns null for undefined values + assert_eq!(data["a"]["b"], json!(null)); // does not panic + ``` +- `type Output = Value` + +### impl IndexMut for Valuewhere I: Index, +- `fn index_mut(&mut self, index: I) -> &mut Value` + Write into a serde_json::Value using the syntax value[0] = ... or value["k"] = ... . + If the index is a number, the value must be an array of length bigger +than the index. Indexing into a value that is not an array or an array +that is too small will panic. + If the index is a string, the value must be an object or null which is +treated like an empty object. If the key is not already present in the +object, it will be inserted with a value of null. Indexing into a value +that is neither an object nor null will panic. + **Examples** + ``` + let mut data = json!({ "x": 0 }); + + // replace an existing key + data["x"] = json!(1); + + // insert a new key + data["y"] = json!([false, false, false]); + + // replace an array value + data["y"][0] = json!(true); + + // inserted a deeply nested key + data["a"]["b"]["c"]["d"] = json!(true); + + println!("{}", data); + ``` + +### impl<'de> IntoDeserializer<'de, Error> for &'de Value +- `type Deserializer = &'de Value` +- `fn into_deserializer(self) -> Self::Deserializer` + +### impl<'de> IntoDeserializer<'de, Error> for Value +- `type Deserializer = Value` +- `fn into_deserializer(self) -> Self::Deserializer` + +### impl PartialEq<&str> for Value +- `fn eq(&self, other: &&str) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for Value +- `fn eq(&self, other: &String) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for &str +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for String +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for bool +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for f32 +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for f64 +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for i16 +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for i32 +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for i64 +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for i8 +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for isize +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for str +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for u16 +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for u32 +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for u64 +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for u8 +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for usize +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a Value +- `fn eq(&self, other: &bool) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a mut Value +- `fn eq(&self, other: &bool) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for Value +- `fn eq(&self, other: &bool) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a Value +- `fn eq(&self, other: &f32) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a mut Value +- `fn eq(&self, other: &f32) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for Value +- `fn eq(&self, other: &f32) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a Value +- `fn eq(&self, other: &f64) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a mut Value +- `fn eq(&self, other: &f64) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for Value +- `fn eq(&self, other: &f64) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a Value +- `fn eq(&self, other: &i16) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a mut Value +- `fn eq(&self, other: &i16) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for Value +- `fn eq(&self, other: &i16) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a Value +- `fn eq(&self, other: &i32) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a mut Value +- `fn eq(&self, other: &i32) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for Value +- `fn eq(&self, other: &i32) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a Value +- `fn eq(&self, other: &i64) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a mut Value +- `fn eq(&self, other: &i64) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for Value +- `fn eq(&self, other: &i64) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a Value +- `fn eq(&self, other: &i8) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a mut Value +- `fn eq(&self, other: &i8) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for Value +- `fn eq(&self, other: &i8) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a Value +- `fn eq(&self, other: &isize) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a mut Value +- `fn eq(&self, other: &isize) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for Value +- `fn eq(&self, other: &isize) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for Value +- `fn eq(&self, other: &str) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a Value +- `fn eq(&self, other: &u16) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a mut Value +- `fn eq(&self, other: &u16) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for Value +- `fn eq(&self, other: &u16) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a Value +- `fn eq(&self, other: &u32) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a mut Value +- `fn eq(&self, other: &u32) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for Value +- `fn eq(&self, other: &u32) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a Value +- `fn eq(&self, other: &u64) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a mut Value +- `fn eq(&self, other: &u64) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for Value +- `fn eq(&self, other: &u64) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a Value +- `fn eq(&self, other: &u8) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a mut Value +- `fn eq(&self, other: &u8) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for Value +- `fn eq(&self, other: &u8) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a Value +- `fn eq(&self, other: &usize) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl<'a> PartialEq for &'a mut Value +- `fn eq(&self, other: &usize) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for Value +- `fn eq(&self, other: &usize) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl PartialEq for Value +- `fn eq(&self, other: &Value) -> bool` +- `fn ne(&self, other: &Rhs) -> bool` + +### impl Serialize for Value +- `fn serialize(&self, serializer: S) -> Resultwhere S: Serializer,` + +### impl Eq for Value + +### impl StructuralPartialEq for Value diff --git a/internal/app/testdata/rustdoc_doc_serdejson_value.html b/internal/app/testdata/rustdoc_doc_serdejson_value.html new file mode 100644 index 0000000..56afbc7 --- /dev/null +++ b/internal/app/testdata/rustdoc_doc_serdejson_value.html @@ -0,0 +1,1028 @@ +Value in serde_json - Rust + + + + +
+ + +Skip to main content

Value

Enum Value 

Source
pub enum Value {
+    Null,
+    Bool(bool),
+    Number(Number),
+    String(String),
+    Array(Vec<Value>),
+    Object(Map<String, Value>),
+}
Expand description

Represents any valid JSON value.

+

See the serde_json::value module documentation for usage examples.

+

Variants§

§

Null

Represents a JSON null value.

+ +
let v = json!(null);
§

Bool(bool)

Represents a JSON boolean.

+ +
let v = json!(true);
§

Number(Number)

Represents a JSON number, whether integer or floating point.

+ +
let v = json!(12.5);
§

String(String)

Represents a JSON string.

+ +
let v = json!("a string");
§

Array(Vec<Value>)

Represents a JSON array.

+ +
let v = json!(["an", "array"]);
§

Object(Map<String, Value>)

Represents a JSON object.

+

By default the map is backed by a BTreeMap. Enable the preserve_order +feature of serde_json to use IndexMap instead, which preserves +entries in the order they are inserted into the map. In particular, this +allows JSON data to be deserialized into a Value and serialized to a +string while retaining the order of map keys in the input.

+ +
let v = json!({ "an": "object" });

Implementations§

Source§

impl Value

Source

pub fn get<I: Index>(&self, index: I) -> Option<&Value>

Index into a JSON array or map. A string index can be used to access a +value in a map, and a usize index can be used to access an element of an +array.

+

Returns None if the type of self does not match the type of the +index, for example if the index is a string and self is an array or a +number. Also returns None if the given key does not exist in the map +or the given index is not within the bounds of the array.

+ +
let object = json!({ "A": 65, "B": 66, "C": 67 });
+assert_eq!(*object.get("A").unwrap(), json!(65));
+
+let array = json!([ "A", "B", "C" ]);
+assert_eq!(*array.get(2).unwrap(), json!("C"));
+
+assert_eq!(array.get("A"), None);
+

Square brackets can also be used to index into a value in a more concise +way. This returns Value::Null in cases where get would have returned +None.

+ +
let object = json!({
+    "A": ["a", "á", "à"],
+    "B": ["b", "b́"],
+    "C": ["c", "ć", "ć̣", "ḉ"],
+});
+assert_eq!(object["B"][0], json!("b"));
+
+assert_eq!(object["D"], json!(null));
+assert_eq!(object[0]["x"]["y"]["z"], json!(null));
Source

pub fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut Value>

Mutably index into a JSON array or map. A string index can be used to +access a value in a map, and a usize index can be used to access an +element of an array.

+

Returns None if the type of self does not match the type of the +index, for example if the index is a string and self is an array or a +number. Also returns None if the given key does not exist in the map +or the given index is not within the bounds of the array.

+ +
let mut object = json!({ "A": 65, "B": 66, "C": 67 });
+*object.get_mut("A").unwrap() = json!(69);
+
+let mut array = json!([ "A", "B", "C" ]);
+*array.get_mut(2).unwrap() = json!("D");
Source

pub fn is_object(&self) -> bool

Returns true if the Value is an Object. Returns false otherwise.

+

For any Value on which is_object returns true, as_object and +as_object_mut are guaranteed to return the map representation of the +object.

+ +
let obj = json!({ "a": { "nested": true }, "b": ["an", "array"] });
+
+assert!(obj.is_object());
+assert!(obj["a"].is_object());
+
+// array, not an object
+assert!(!obj["b"].is_object());
Source

pub fn as_object(&self) -> Option<&Map<String, Value>>

If the Value is an Object, returns the associated Map. Returns None +otherwise.

+ +
let v = json!({ "a": { "nested": true }, "b": ["an", "array"] });
+
+// The length of `{"nested": true}` is 1 entry.
+assert_eq!(v["a"].as_object().unwrap().len(), 1);
+
+// The array `["an", "array"]` is not an object.
+assert_eq!(v["b"].as_object(), None);
Source

pub fn as_object_mut(&mut self) -> Option<&mut Map<String, Value>>

If the Value is an Object, returns the associated mutable Map. +Returns None otherwise.

+ +
let mut v = json!({ "a": { "nested": true } });
+
+v["a"].as_object_mut().unwrap().clear();
+assert_eq!(v, json!({ "a": {} }));
Source

pub fn is_array(&self) -> bool

Returns true if the Value is an Array. Returns false otherwise.

+

For any Value on which is_array returns true, as_array and +as_array_mut are guaranteed to return the vector representing the +array.

+ +
let obj = json!({ "a": ["an", "array"], "b": { "an": "object" } });
+
+assert!(obj["a"].is_array());
+
+// an object, not an array
+assert!(!obj["b"].is_array());
Source

pub fn as_array(&self) -> Option<&Vec<Value>>

If the Value is an Array, returns the associated vector. Returns None +otherwise.

+ +
let v = json!({ "a": ["an", "array"], "b": { "an": "object" } });
+
+// The length of `["an", "array"]` is 2 elements.
+assert_eq!(v["a"].as_array().unwrap().len(), 2);
+
+// The object `{"an": "object"}` is not an array.
+assert_eq!(v["b"].as_array(), None);
Source

pub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>

If the Value is an Array, returns the associated mutable vector. +Returns None otherwise.

+ +
let mut v = json!({ "a": ["an", "array"] });
+
+v["a"].as_array_mut().unwrap().clear();
+assert_eq!(v, json!({ "a": [] }));
Source

pub fn is_string(&self) -> bool

Returns true if the Value is a String. Returns false otherwise.

+

For any Value on which is_string returns true, as_str is guaranteed +to return the string slice.

+ +
let v = json!({ "a": "some string", "b": false });
+
+assert!(v["a"].is_string());
+
+// The boolean `false` is not a string.
+assert!(!v["b"].is_string());
Source

pub fn as_str(&self) -> Option<&str>

If the Value is a String, returns the associated str. Returns None +otherwise.

+ +
let v = json!({ "a": "some string", "b": false });
+
+assert_eq!(v["a"].as_str(), Some("some string"));
+
+// The boolean `false` is not a string.
+assert_eq!(v["b"].as_str(), None);
+
+// JSON values are printed in JSON representation, so strings are in quotes.
+//
+//    The value is: "some string"
+println!("The value is: {}", v["a"]);
+
+// Rust strings are printed without quotes.
+//
+//    The value is: some string
+println!("The value is: {}", v["a"].as_str().unwrap());
Source

pub fn is_number(&self) -> bool

Returns true if the Value is a Number. Returns false otherwise.

+ +
let v = json!({ "a": 1, "b": "2" });
+
+assert!(v["a"].is_number());
+
+// The string `"2"` is a string, not a number.
+assert!(!v["b"].is_number());
Source

pub fn as_number(&self) -> Option<&Number>

If the Value is a Number, returns the associated Number. Returns +None otherwise.

+ +
let v = json!({ "a": 1, "b": 2.2, "c": -3, "d": "4" });
+
+assert_eq!(v["a"].as_number(), Some(&Number::from(1u64)));
+assert_eq!(v["b"].as_number(), Some(&Number::from_f64(2.2).unwrap()));
+assert_eq!(v["c"].as_number(), Some(&Number::from(-3i64)));
+
+// The string `"4"` is not a number.
+assert_eq!(v["d"].as_number(), None);
Source

pub fn is_i64(&self) -> bool

Returns true if the Value is an integer between i64::MIN and +i64::MAX.

+

For any Value on which is_i64 returns true, as_i64 is guaranteed to +return the integer value.

+ +
let big = i64::max_value() as u64 + 10;
+let v = json!({ "a": 64, "b": big, "c": 256.0 });
+
+assert!(v["a"].is_i64());
+
+// Greater than i64::MAX.
+assert!(!v["b"].is_i64());
+
+// Numbers with a decimal point are not considered integers.
+assert!(!v["c"].is_i64());
Source

pub fn is_u64(&self) -> bool

Returns true if the Value is an integer between zero and u64::MAX.

+

For any Value on which is_u64 returns true, as_u64 is guaranteed to +return the integer value.

+ +
let v = json!({ "a": 64, "b": -64, "c": 256.0 });
+
+assert!(v["a"].is_u64());
+
+// Negative integer.
+assert!(!v["b"].is_u64());
+
+// Numbers with a decimal point are not considered integers.
+assert!(!v["c"].is_u64());
Source

pub fn is_f64(&self) -> bool

Returns true if the Value is a number that can be represented by f64.

+

For any Value on which is_f64 returns true, as_f64 is guaranteed to +return the floating point value.

+

Currently this function returns true if and only if both is_i64 and +is_u64 return false but this is not a guarantee in the future.

+ +
let v = json!({ "a": 256.0, "b": 64, "c": -64 });
+
+assert!(v["a"].is_f64());
+
+// Integers.
+assert!(!v["b"].is_f64());
+assert!(!v["c"].is_f64());
Source

pub fn as_i64(&self) -> Option<i64>

If the Value is an integer, represent it as i64 if possible. Returns +None otherwise.

+ +
let big = i64::max_value() as u64 + 10;
+let v = json!({ "a": 64, "b": big, "c": 256.0 });
+
+assert_eq!(v["a"].as_i64(), Some(64));
+assert_eq!(v["b"].as_i64(), None);
+assert_eq!(v["c"].as_i64(), None);
Source

pub fn as_u64(&self) -> Option<u64>

If the Value is an integer, represent it as u64 if possible. Returns +None otherwise.

+ +
let v = json!({ "a": 64, "b": -64, "c": 256.0 });
+
+assert_eq!(v["a"].as_u64(), Some(64));
+assert_eq!(v["b"].as_u64(), None);
+assert_eq!(v["c"].as_u64(), None);
Source

pub fn as_f64(&self) -> Option<f64>

If the Value is a number, represent it as f64 if possible. Returns +None otherwise.

+ +
let v = json!({ "a": 256.0, "b": 64, "c": -64 });
+
+assert_eq!(v["a"].as_f64(), Some(256.0));
+assert_eq!(v["b"].as_f64(), Some(64.0));
+assert_eq!(v["c"].as_f64(), Some(-64.0));
Source

pub fn is_boolean(&self) -> bool

Returns true if the Value is a Boolean. Returns false otherwise.

+

For any Value on which is_boolean returns true, as_bool is +guaranteed to return the boolean value.

+ +
let v = json!({ "a": false, "b": "false" });
+
+assert!(v["a"].is_boolean());
+
+// The string `"false"` is a string, not a boolean.
+assert!(!v["b"].is_boolean());
Source

pub fn as_bool(&self) -> Option<bool>

If the Value is a Boolean, returns the associated bool. Returns None +otherwise.

+ +
let v = json!({ "a": false, "b": "false" });
+
+assert_eq!(v["a"].as_bool(), Some(false));
+
+// The string `"false"` is a string, not a boolean.
+assert_eq!(v["b"].as_bool(), None);
Source

pub fn is_null(&self) -> bool

Returns true if the Value is a Null. Returns false otherwise.

+

For any Value on which is_null returns true, as_null is guaranteed +to return Some(()).

+ +
let v = json!({ "a": null, "b": false });
+
+assert!(v["a"].is_null());
+
+// The boolean `false` is not null.
+assert!(!v["b"].is_null());
Source

pub fn as_null(&self) -> Option<()>

If the Value is a Null, returns (). Returns None otherwise.

+ +
let v = json!({ "a": null, "b": false });
+
+assert_eq!(v["a"].as_null(), Some(()));
+
+// The boolean `false` is not null.
+assert_eq!(v["b"].as_null(), None);
Source

pub fn pointer(&self, pointer: &str) -> Option<&Value>

Looks up a value by a JSON Pointer.

+

JSON Pointer defines a string syntax for identifying a specific value +within a JavaScript Object Notation (JSON) document.

+

A Pointer is a Unicode string with the reference tokens separated by /. +Inside tokens / is replaced by ~1 and ~ is replaced by ~0. The +addressed value is returned and if there is no such value None is +returned.

+

For more information read RFC6901.

+
§Examples
+
let data = json!({
+    "x": {
+        "y": ["z", "zz"]
+    }
+});
+
+assert_eq!(data.pointer("/x/y/1").unwrap(), &json!("zz"));
+assert_eq!(data.pointer("/a/b/c"), None);
Source

pub fn pointer_mut(&mut self, pointer: &str) -> Option<&mut Value>

Looks up a value by a JSON Pointer and returns a mutable reference to +that value.

+

JSON Pointer defines a string syntax for identifying a specific value +within a JavaScript Object Notation (JSON) document.

+

A Pointer is a Unicode string with the reference tokens separated by /. +Inside tokens / is replaced by ~1 and ~ is replaced by ~0. The +addressed value is returned and if there is no such value None is +returned.

+

For more information read RFC6901.

+
§Example of Use
+
use serde_json::Value;
+
+fn main() {
+    let s = r#"{"x": 1.0, "y": 2.0}"#;
+    let mut value: Value = serde_json::from_str(s).unwrap();
+
+    // Check value using read-only pointer
+    assert_eq!(value.pointer("/x"), Some(&1.0.into()));
+    // Change value with direct assignment
+    *value.pointer_mut("/x").unwrap() = 1.5.into();
+    // Check that new value was written
+    assert_eq!(value.pointer("/x"), Some(&1.5.into()));
+    // Or change the value only if it exists
+    value.pointer_mut("/x").map(|v| *v = 1.5.into());
+
+    // "Steal" ownership of a value. Can replace with any valid Value.
+    let old_x = value.pointer_mut("/x").map(Value::take).unwrap();
+    assert_eq!(old_x, 1.5);
+    assert_eq!(value.pointer("/x").unwrap(), &Value::Null);
+}
Source

pub fn take(&mut self) -> Value

Takes the value out of the Value, leaving a Null in its place.

+ +
let mut v = json!({ "x": "y" });
+assert_eq!(v["x"].take(), json!("y"));
+assert_eq!(v, json!({ "x": null }));
Source

pub fn sort_all_objects(&mut self)

Reorders the entries of all Value::Object nested within this JSON +value according to str’s usual ordering.

+

If serde_json’s “preserve_order” feature is not enabled, this method +does no work because all JSON maps are always kept in a sorted state.

+

If serde_json’s “preserve_order” feature is enabled, this method +destroys the original source order or insertion order of the JSON +objects in favor of an alphanumerical order that matches how a BTreeMap +with the same contents would be ordered.

+

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

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

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

impl Default for &Value

Source§

fn default() -> Self

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

impl Default for Value

The default value is Value::Null.

+

This is useful for handling omitted Value fields when deserializing.

+

§Examples

+
use serde_json::Value;
+
+#[derive(Deserialize)]
+struct Settings {
+    level: i32,
+    #[serde(default)]
+    extras: Value,
+}
+
+let data = r#" { "level": 42 } "#;
+let s: Settings = serde_json::from_str(data)?;
+
+assert_eq!(s.level, 42);
+assert_eq!(s.extras, Value::Null);
Source§

fn default() -> Value

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

impl<'de> Deserialize<'de> for Value

Source§

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

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

impl<'de> Deserializer<'de> for &'de Value

Source§

type Error = Error

The error type that can be returned if some error occurs during +deserialization.
Source§

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Require the Deserializer to figure out how to drive the visitor based +on what data type is in the input. Read more
Source§

fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i8 value.
Source§

fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i16 value.
Source§

fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i32 value.
Source§

fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i64 value.
Source§

fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i128 value. Read more
Source§

fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a u8 value.
Source§

fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a u16 value.
Source§

fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a u32 value.
Source§

fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a u64 value.
Source§

fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an u128 value. Read more
Source§

fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a f32 value.
Source§

fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a f64 value.
Source§

fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an optional value. Read more
Source§

fn deserialize_enum<V>( + self, + name: &'static str, + variants: &'static [&'static str], + visitor: V, +) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an enum value with a +particular name and possible variants.
Source§

fn deserialize_newtype_struct<V>( + self, + name: &'static str, + visitor: V, +) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a newtype struct with a +particular name.
Source§

fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a bool value.
Source§

fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a char value.
Source§

fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a string value and does +not benefit from taking ownership of buffered data owned by the +Deserializer. Read more
Source§

fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a string value and would +benefit from taking ownership of buffered data owned by the +Deserializer. Read more
Source§

fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a byte array and does not +benefit from taking ownership of buffered data owned by the +Deserializer. Read more
Source§

fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a byte array and would +benefit from taking ownership of buffered data owned by the +Deserializer. Read more
Source§

fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit value.
Source§

fn deserialize_unit_struct<V>( + self, + _name: &'static str, + visitor: V, +) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit struct with a +particular name.
Source§

fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values.
Source§

fn deserialize_tuple<V>( + self, + _len: usize, + visitor: V, +) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values and +knows how many values there are without looking at the serialized data.
Source§

fn deserialize_tuple_struct<V>( + self, + _name: &'static str, + _len: usize, + visitor: V, +) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a tuple struct with a +particular name and number of fields.
Source§

fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a map of key-value pairs.
Source§

fn deserialize_struct<V>( + self, + _name: &'static str, + _fields: &'static [&'static str], + visitor: V, +) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a struct with a particular +name and fields.
Source§

fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting the name of a struct +field or the discriminant of an enum variant.
Source§

fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type needs to deserialize a value whose type +doesn’t matter because it is ignored. Read more
Source§

fn is_human_readable(&self) -> bool

Determine whether Deserialize implementations should expect to +deserialize their human-readable form. Read more
Source§

impl<'de> Deserializer<'de> for Value

Source§

type Error = Error

The error type that can be returned if some error occurs during +deserialization.
Source§

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Require the Deserializer to figure out how to drive the visitor based +on what data type is in the input. Read more
Source§

fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i8 value.
Source§

fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i16 value.
Source§

fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i32 value.
Source§

fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i64 value.
Source§

fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an i128 value. Read more
Source§

fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a u8 value.
Source§

fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a u16 value.
Source§

fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a u32 value.
Source§

fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a u64 value.
Source§

fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an u128 value. Read more
Source§

fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a f32 value.
Source§

fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a f64 value.
Source§

fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an optional value. Read more
Source§

fn deserialize_enum<V>( + self, + name: &'static str, + variants: &'static [&'static str], + visitor: V, +) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting an enum value with a +particular name and possible variants.
Source§

fn deserialize_newtype_struct<V>( + self, + name: &'static str, + visitor: V, +) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a newtype struct with a +particular name.
Source§

fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a bool value.
Source§

fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a char value.
Source§

fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a string value and does +not benefit from taking ownership of buffered data owned by the +Deserializer. Read more
Source§

fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a string value and would +benefit from taking ownership of buffered data owned by the +Deserializer. Read more
Source§

fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a byte array and does not +benefit from taking ownership of buffered data owned by the +Deserializer. Read more
Source§

fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a byte array and would +benefit from taking ownership of buffered data owned by the +Deserializer. Read more
Source§

fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit value.
Source§

fn deserialize_unit_struct<V>( + self, + _name: &'static str, + visitor: V, +) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a unit struct with a +particular name.
Source§

fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values.
Source§

fn deserialize_tuple<V>( + self, + _len: usize, + visitor: V, +) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values and +knows how many values there are without looking at the serialized data.
Source§

fn deserialize_tuple_struct<V>( + self, + _name: &'static str, + _len: usize, + visitor: V, +) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a tuple struct with a +particular name and number of fields.
Source§

fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a map of key-value pairs.
Source§

fn deserialize_struct<V>( + self, + _name: &'static str, + _fields: &'static [&'static str], + visitor: V, +) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting a struct with a particular +name and fields.
Source§

fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type is expecting the name of a struct +field or the discriminant of an enum variant.
Source§

fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Error>
where + V: Visitor<'de>,

Hint that the Deserialize type needs to deserialize a value whose type +doesn’t matter because it is ignored. Read more
Source§

fn is_human_readable(&self) -> bool

Determine whether Deserialize implementations should expect to +deserialize their human-readable form. Read more
Source§

impl Display for Value

Source§

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

Display a JSON value as a string.

+ +
let json = json!({ "city": "London", "street": "10 Downing Street" });
+
+// Compact format:
+//
+// {"city":"London","street":"10 Downing Street"}
+let compact = format!("{}", json);
+assert_eq!(compact,
+    "{\"city\":\"London\",\"street\":\"10 Downing Street\"}");
+
+// Pretty format:
+//
+// {
+//   "city": "London",
+//   "street": "10 Downing Street"
+// }
+let pretty = format!("{:#}", json);
+assert_eq!(pretty,
+    "{\n  \"city\": \"London\",\n  \"street\": \"10 Downing Street\"\n}");
Source§

impl<T: Clone + Into<Value>> From<&[T]> for Value

Source§

fn from(f: &[T]) -> Self

Convert a slice to Value::Array.

+
§Examples
+
use serde_json::Value;
+
+let v: &[&str] = &["lorem", "ipsum", "dolor"];
+let x: Value = v.into();
Source§

impl From<&str> for Value

Source§

fn from(f: &str) -> Self

Convert string slice to Value::String.

+
§Examples
+
use serde_json::Value;
+
+let s: &str = "lorem";
+let x: Value = s.into();
Source§

impl<T: Into<Value>, const N: usize> From<[T; N]> for Value

Source§

fn from(array: [T; N]) -> Self

Converts to this type from the input type.
Source§

impl From<()> for Value

Source§

fn from((): ()) -> Self

Convert () to Value::Null.

+
§Examples
+
use serde_json::Value;
+
+let u = ();
+let x: Value = u.into();
Source§

impl<'a> From<Cow<'a, str>> for Value

Source§

fn from(f: Cow<'a, str>) -> Self

Convert copy-on-write string to Value::String.

+
§Examples
+
use serde_json::Value;
+use std::borrow::Cow;
+
+let s: Cow<str> = Cow::Borrowed("lorem");
+let x: Value = s.into();
+
use serde_json::Value;
+use std::borrow::Cow;
+
+let s: Cow<str> = Cow::Owned("lorem".to_owned());
+let x: Value = s.into();
Source§

impl From<Map<String, Value>> for Value

Source§

fn from(f: Map<String, Value>) -> Self

Convert map (with string keys) to Value::Object.

+
§Examples
+
use serde_json::{Map, Value};
+
+let mut m = Map::new();
+m.insert("Lorem".to_owned(), "ipsum".into());
+let x: Value = m.into();
Source§

impl From<Number> for Value

Source§

fn from(f: Number) -> Self

Convert Number to Value::Number.

+
§Examples
+
use serde_json::{Number, Value};
+
+let n = Number::from(7);
+let x: Value = n.into();
Source§

impl<T> From<Option<T>> for Value
where + T: Into<Value>,

Source§

fn from(opt: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(f: String) -> Self

Convert String to Value::String.

+
§Examples
+
use serde_json::Value;
+
+let s: String = "lorem".to_owned();
+let x: Value = s.into();
Source§

impl<T: Into<Value>> From<Vec<T>> for Value

Source§

fn from(f: Vec<T>) -> Self

Convert a Vec to Value::Array.

+
§Examples
+
use serde_json::Value;
+
+let v = vec!["lorem", "ipsum", "dolor"];
+let x: Value = v.into();
Source§

impl From<bool> for Value

Source§

fn from(f: bool) -> Self

Convert boolean to Value::Bool.

+
§Examples
+
use serde_json::Value;
+
+let b = false;
+let x: Value = b.into();
Source§

impl From<f32> for Value

Source§

fn from(f: f32) -> Self

Convert 32-bit floating point number to Value::Number, or +Value::Null if infinite or NaN.

+
§Examples
+
use serde_json::Value;
+
+let f: f32 = 13.37;
+let x: Value = f.into();
Source§

impl From<f64> for Value

Source§

fn from(f: f64) -> Self

Convert 64-bit floating point number to Value::Number, or +Value::Null if infinite or NaN.

+
§Examples
+
use serde_json::Value;
+
+let f: f64 = 13.37;
+let x: Value = f.into();
Source§

impl From<i16> for Value

Source§

fn from(n: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(n: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(n: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(n: i8) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for Value

Source§

fn from(n: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(n: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(n: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(n: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(n: u8) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for Value

Source§

fn from(n: usize) -> Self

Converts to this type from the input type.
Source§

impl<K: Into<String>, V: Into<Value>> FromIterator<(K, V)> for Value

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Create a Value::Object by collecting an iterator of key-value pairs.

+
§Examples
+
use serde_json::Value;
+
+let v: Vec<_> = vec![("lorem", 40), ("ipsum", 2)];
+let x: Value = v.into_iter().collect();
Source§

impl<T: Into<Value>> FromIterator<T> for Value

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Create a Value::Array by collecting an iterator of array elements.

+
§Examples
+
use serde_json::Value;
+
+let v = std::iter::repeat(42).take(5);
+let x: Value = v.collect();
+
use serde_json::Value;
+
+let v: Vec<_> = vec!["lorem", "ipsum", "dolor"];
+let x: Value = v.into_iter().collect();
+
use std::iter::FromIterator;
+use serde_json::Value;
+
+let x: Value = Value::from_iter(vec!["lorem", "ipsum", "dolor"]);
Source§

impl FromStr for Value

Source§

type Err = Error

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

fn from_str(s: &str) -> Result<Value, Error>

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

impl Hash for Value

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where + H: Hasher, + Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<I> Index<I> for Value
where + I: Index,

Source§

fn index(&self, index: I) -> &Value

Index into a serde_json::Value using the syntax value[0] or +value["k"].

+

Returns Value::Null if the type of self does not match the type of +the index, for example if the index is a string and self is an array +or a number. Also returns Value::Null if the given key does not exist +in the map or the given index is not within the bounds of the array.

+

For retrieving deeply nested values, you should have a look at the +Value::pointer method.

+
§Examples
+
let data = json!({
+    "x": {
+        "y": ["z", "zz"]
+    }
+});
+
+assert_eq!(data["x"]["y"], json!(["z", "zz"]));
+assert_eq!(data["x"]["y"][0], json!("z"));
+
+assert_eq!(data["a"], json!(null)); // returns null for undefined values
+assert_eq!(data["a"]["b"], json!(null)); // does not panic
Source§

type Output = Value

The returned type after indexing.
Source§

impl<I> IndexMut<I> for Value
where + I: Index,

Source§

fn index_mut(&mut self, index: I) -> &mut Value

Write into a serde_json::Value using the syntax value[0] = ... or +value["k"] = ....

+

If the index is a number, the value must be an array of length bigger +than the index. Indexing into a value that is not an array or an array +that is too small will panic.

+

If the index is a string, the value must be an object or null which is +treated like an empty object. If the key is not already present in the +object, it will be inserted with a value of null. Indexing into a value +that is neither an object nor null will panic.

+
§Examples
+
let mut data = json!({ "x": 0 });
+
+// replace an existing key
+data["x"] = json!(1);
+
+// insert a new key
+data["y"] = json!([false, false, false]);
+
+// replace an array value
+data["y"][0] = json!(true);
+
+// inserted a deeply nested key
+data["a"]["b"]["c"]["d"] = json!(true);
+
+println!("{}", data);
Source§

impl<'de> IntoDeserializer<'de, Error> for &'de Value

Source§

type Deserializer = &'de Value

The type of the deserializer being converted into.
Source§

fn into_deserializer(self) -> Self::Deserializer

Convert this value into a deserializer.
Source§

impl<'de> IntoDeserializer<'de, Error> for Value

Source§

type Deserializer = Value

The type of the deserializer being converted into.
Source§

fn into_deserializer(self) -> Self::Deserializer

Convert this value into a deserializer.
Source§

impl PartialEq<&str> for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<String> for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Value> for &str

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Value> for String

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Value> for bool

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Value> for f32

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Value> for f64

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Value> for i16

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Value> for i32

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Value> for i64

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Value> for i8

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Value> for isize

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Value> for str

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Value> for u16

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Value> for u32

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Value> for u64

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Value> for u8

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Value> for usize

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<bool> for &'a Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<bool> for &'a mut Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<bool> for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<f32> for &'a Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<f32> for &'a mut Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<f32> for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<f64> for &'a Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<f64> for &'a mut Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<f64> for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<i16> for &'a Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<i16> for &'a mut Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<i16> for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<i32> for &'a Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<i32> for &'a mut Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<i32> for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<i64> for &'a Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<i64> for &'a mut Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<i64> for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<i8> for &'a Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<i8> for &'a mut Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<i8> for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<isize> for &'a Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<isize> for &'a mut Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<isize> for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<str> for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<u16> for &'a Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<u16> for &'a mut Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<u16> for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<u32> for &'a Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<u32> for &'a mut Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<u32> for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<u64> for &'a Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<u64> for &'a mut Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<u64> for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<u8> for &'a Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<u8> for &'a mut Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<u8> for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<usize> for &'a Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<'a> PartialEq<usize> for &'a mut Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<usize> for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Serialize for Value

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 Eq for Value

Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

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> 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, 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> DeserializeOwned for T
where + T: for<'de> Deserialize<'de>,

\ No newline at end of file