pub type EncodeResult = Result<(), EncoderError>;
pub type DecodeResult<T> = Result<T, DecoderError>;
-fn escape_str(wr: &mut fmt::Write, v: &str) -> EncodeResult {
+fn escape_str(wr: &mut dyn fmt::Write, v: &str) -> EncodeResult {
wr.write_str("\"")?;
let mut start = 0;
Ok(())
}
-fn escape_char(writer: &mut fmt::Write, v: char) -> EncodeResult {
+fn escape_char(writer: &mut dyn fmt::Write, v: char) -> EncodeResult {
escape_str(writer, v.encode_utf8(&mut [0; 4]))
}
-fn spaces(wr: &mut fmt::Write, mut n: usize) -> EncodeResult {
+fn spaces(wr: &mut dyn fmt::Write, mut n: usize) -> EncodeResult {
const BUF: &'static str = " ";
while n >= BUF.len() {
/// A structure for implementing serialization to JSON.
pub struct Encoder<'a> {
- writer: &'a mut (fmt::Write+'a),
+ writer: &'a mut (dyn fmt::Write+'a),
is_emitting_map_key: bool,
}
impl<'a> Encoder<'a> {
/// Creates a new JSON encoder whose output will be written to the writer
/// specified.
- pub fn new(writer: &'a mut fmt::Write) -> Encoder<'a> {
+ pub fn new(writer: &'a mut dyn fmt::Write) -> Encoder<'a> {
Encoder { writer: writer, is_emitting_map_key: false, }
}
}
/// Another encoder for JSON, but prints out human-readable JSON instead of
/// compact data
pub struct PrettyEncoder<'a> {
- writer: &'a mut (fmt::Write+'a),
+ writer: &'a mut (dyn fmt::Write+'a),
curr_indent: usize,
indent: usize,
is_emitting_map_key: bool,
impl<'a> PrettyEncoder<'a> {
/// Creates a new encoder whose output will be written to the specified writer
- pub fn new(writer: &'a mut fmt::Write) -> PrettyEncoder<'a> {
+ pub fn new(writer: &'a mut dyn fmt::Write) -> PrettyEncoder<'a> {
PrettyEncoder {
writer,
curr_indent: 0,
}
/// Decodes a json value from an `&mut io::Read`
-pub fn from_reader(rdr: &mut Read) -> Result<Json, BuilderError> {
+pub fn from_reader(rdr: &mut dyn Read) -> Result<Json, BuilderError> {
let mut contents = Vec::new();
match rdr.read_to_end(&mut contents) {
Ok(c) => c,