# [−][src]Struct rustc_serialize::json::Encoder

    pub struct Encoder<'a> { /* fields omitted */ }

A structure for implementing serialization to JSON.

## Methods

### `impl<'a> Encoder<'a>`[src]

#### `pub fn new_pretty(writer: &'a mut dyn Write) -> Encoder<'a>`[src]

Creates a new encoder whose output will be written in human-readable JSON to the specified writer

#### `pub fn new(writer: &'a mut dyn Write) -> Encoder<'a>`[src]

Creates a new encoder whose output will be written in compact JSON to the specified writer

#### `pub fn set_indent(&mut self, new_indent: u32) -> Result<(), ()>`[src]

Set the number of spaces to indent for each level. This is safe to set during encoding.

## Trait Implementations

### `impl<'a> Encoder for Encoder<'a>`[src]

#### `type Error = EncoderError`

The error type for method results.

#### `fn emit_nil(&mut self) -> EncodeResult<()>`[src]

Emit a nil value. Read more

#### `fn emit_usize(&mut self, v: usize) -> EncodeResult<()>`[src]

Emit a usize value.

#### `fn emit_u64(&mut self, v: u64) -> EncodeResult<()>`[src]

Emit a u64 value.

#### `fn emit_u32(&mut self, v: u32) -> EncodeResult<()>`[src]

Emit a u32 value.

#### `fn emit_u16(&mut self, v: u16) -> EncodeResult<()>`[src]

Emit a u16 value.

#### `fn emit_u8(&mut self, v: u8) -> EncodeResult<()>`[src]

Emit a u8 value.

#### `fn emit_isize(&mut self, v: isize) -> EncodeResult<()>`[src]

Emit a isize value.

#### `fn emit_i64(&mut self, v: i64) -> EncodeResult<()>`[src]

Emit a i64 value.

#### `fn emit_i32(&mut self, v: i32) -> EncodeResult<()>`[src]

Emit a i32 value.

#### `fn emit_i16(&mut self, v: i16) -> EncodeResult<()>`[src]

Emit a i16 value.

#### `fn emit_i8(&mut self, v: i8) -> EncodeResult<()>`[src]

Emit a i8 value.

#### `fn emit_bool(&mut self, v: bool) -> EncodeResult<()>`[src]

Emit a bool value. Read more

#### `fn emit_f64(&mut self, v: f64) -> EncodeResult<()>`[src]

Emit a f64 value.

#### `fn emit_f32(&mut self, v: f32) -> EncodeResult<()>`[src]

Emit a f32 value.

#### `fn emit_char(&mut self, v: char) -> EncodeResult<()>`[src]

Emit a char value. Read more

#### `fn emit_str(&mut self, v: &str) -> EncodeResult<()>`[src]

Emit a string value.

#### `fn emit_enum<F>(&mut self, _name: &str, f: F) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit an enumeration value. Read more

#### `fn emit_enum_variant<F>(
&mut self,
name: &str,
_id: usize,
cnt: usize,
f: F
) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit a enumeration variant value with no or unnamed data. Read more

#### `fn emit_enum_variant_arg<F>(&mut self, idx: usize, f: F) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit an unnamed data item for an enumeration variant. Read more

#### `fn emit_enum_struct_variant<F>(
&mut self,
name: &str,
id: usize,
cnt: usize,
f: F
) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit a enumeration variant value with no or named data. Read more

#### `fn emit_enum_struct_variant_field<F>(
&mut self,
_: &str,
idx: usize,
f: F
) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit a named data item for an enumeration variant. Read more

#### `fn emit_struct<F>(&mut self, _: &str, len: usize, f: F) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit a struct value. Read more

#### `fn emit_struct_field<F>(
&mut self,
name: &str,
idx: usize,
f: F
) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit a field item for a struct. Read more

#### `fn emit_tuple<F>(&mut self, len: usize, f: F) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit a tuple value. Read more

#### `fn emit_tuple_arg<F>(&mut self, idx: usize, f: F) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit a data item for a tuple. Read more

#### `fn emit_tuple_struct<F>(
&mut self,
_: &str,
len: usize,
f: F
) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit a tuple struct value. Read more

#### `fn emit_tuple_struct_arg<F>(&mut self, idx: usize, f: F) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit a data item for a tuple struct. Read more

#### `fn emit_option<F>(&mut self, f: F) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit an optional value. Read more

#### `fn emit_option_none(&mut self) -> EncodeResult<()>`[src]

Emit the `None` optional value. Read more

#### `fn emit_option_some<F>(&mut self, f: F) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit the `Some(x)` optional value. Read more

#### `fn emit_seq<F>(&mut self, len: usize, f: F) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit a sequence of values. Read more

#### `fn emit_seq_elt<F>(&mut self, idx: usize, f: F) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit an element in a sequence. Read more

#### `fn emit_map<F>(&mut self, len: usize, f: F) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit an associative container (map). Read more

#### `fn emit_map_elt_key<F>(&mut self, idx: usize, f: F) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit the key for an entry in a map. Read more

#### `fn emit_map_elt_val<F>(&mut self, _idx: usize, f: F) -> EncodeResult<()> where
F: FnOnce(&mut Encoder<'a>) -> EncodeResult<()>,` [src]

Emit the value for an entry in a map. Read more

## Auto Trait Implementations

### `impl<'a> !Send for Encoder<'a>`

### `impl<'a> Unpin for Encoder<'a>`

### `impl<'a> !Sync for Encoder<'a>`

### `impl<'a> !UnwindSafe for Encoder<'a>`

### `impl<'a> !RefUnwindSafe for Encoder<'a>`

## Blanket Implementations

### `impl<T, U> Into<U> for T where
U: From<T>,` [src]

#### `fn into(self) -> U`[src]

Performs the conversion.

### `impl<T> From<T> for T`[src]

#### `fn from(t: T) -> T`[src]

Performs the conversion.

### `impl<T, U> TryFrom<U> for T where
U: Into<T>,` [src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

#### `fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>`[src]

Performs the conversion.

### `impl<T, U> TryInto<U> for T where
U: TryFrom<T>,` [src]

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

The type returned in the event of a conversion error.

#### `fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>`[src]

Performs the conversion.

### `impl<T> BorrowMut<T> for T where
T: ?Sized,` [src]

#### `fn borrow_mut(&mut self) -> &mut T`[src]

Mutably borrows from an owned value. Read more

### `impl<T> Borrow<T> for T where
T: ?Sized,` [src]

#### `fn borrow(&self) -> &T`[src]

Immutably borrows from an owned value. Read more

### `impl<T> Any for T where
T: 'static + ?Sized,` [src]

#### `fn type_id(&self) -> TypeId`[src]

Gets the `TypeId` of `self`. Read more

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)