Trait ToJsonWriter

Source
pub trait ToJsonWriter {
    // Required methods
    fn to_json_writer<W>(&self, writer: W) -> Result<(), Error>
       where W: Write;
    fn to_json_writer_pretty<W>(&self, writer: W) -> Result<(), Error>
       where W: Write;
}

Required Methods§

Source

fn to_json_writer<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

Convert to json writer.

use std::fs::File;
use serde::Serialize;
use serde_valid::json::ToJsonWriter;
use serde_valid::Validate;

#[derive(Debug, Validate, Serialize)]
struct TestStruct {
    #[validate(maximum = 100)]
    val: i32,
}
let s = TestStruct { val: 10 };

assert!(s.to_json_writer(File::open("foo.txt").unwrap()).is_ok());
Source

fn to_json_writer_pretty<W>(&self, writer: W) -> Result<(), Error>
where W: Write,

Convert to pretty json writer.

use std::fs::File;
use serde::Serialize;
use serde_valid::json::ToJsonWriter;
use serde_valid::Validate;

#[derive(Debug, Validate, Serialize)]
struct TestStruct {
    #[validate(maximum = 100)]
    val: i32,
}
let s = TestStruct { val: 10 };

assert!(s.to_json_writer_pretty(File::open("foo.txt").unwrap()).is_ok());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§