Skip to content

Commit

Permalink
Update README example slightly
Browse files Browse the repository at this point in the history
Fix bare_trait_objects warning.
Remove unnecessary mut borrows.
  • Loading branch information
pyfisch committed Jun 12, 2019
1 parent d8e9c4a commit ecb768c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ struct Mascot {
year_of_birth: u32,
}

fn main() -> Result<(), Box<Error>> {
fn main() -> Result<(), Box<dyn Error>> {
let ferris = Mascot {
name: "Ferris".to_owned(),
species: "crab".to_owned(),
year_of_birth: 2015,
};

let mut ferris_file = File::create("examples/ferris.cbor")?;
let ferris_file = File::create("examples/ferris.cbor")?;
// Write Ferris to the given file.
// Instead of a file you can use any type that implements `io::Write`
// like a HTTP body, database connection etc.
serde_cbor::to_writer(&mut ferris_file, &ferris)?;
serde_cbor::to_writer(ferris_file, &ferris)?;

let mut tux_file = File::open("examples/tux.cbor")?;
let tux_file = File::open("examples/tux.cbor")?;
// Load Tux from a file.
// Serde CBOR performs roundtrip serialization meaning that
// the data will not change in any way.
let tux: Mascot = serde_cbor::from_reader(&mut tux_file)?;
let tux: Mascot = serde_cbor::from_reader(tux_file)?;

println!("{:?}", tux);
// prints: Mascot { name: "Tux", species: "penguin", year_of_birth: 1996 }
Expand Down
10 changes: 5 additions & 5 deletions examples/readme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ struct Mascot {
year_of_birth: u32,
}

fn main() -> Result<(), Box<Error>> {
fn main() -> Result<(), Box<dyn Error>> {
let ferris = Mascot {
name: "Ferris".to_owned(),
species: "crab".to_owned(),
year_of_birth: 2015,
};

let mut ferris_file = File::create("examples/ferris.cbor")?;
let ferris_file = File::create("examples/ferris.cbor")?;
// Write Ferris to the given file.
// Instead of a file you can use any type that implements `io::Write`
// like a HTTP body, database connection etc.
serde_cbor::to_writer(&mut ferris_file, &ferris)?;
serde_cbor::to_writer(ferris_file, &ferris)?;

let mut tux_file = File::open("examples/tux.cbor")?;
let tux_file = File::open("examples/tux.cbor")?;
// Load Tux from a file.
// Serde CBOR performs roundtrip serialization meaning that
// the data will not change in any way.
let tux: Mascot = serde_cbor::from_reader(&mut tux_file)?;
let tux: Mascot = serde_cbor::from_reader(tux_file)?;

println!("{:?}", tux);
// prints: Mascot { name: "Tux", species: "penguin", year_of_birth: 1996 }
Expand Down

0 comments on commit ecb768c

Please sign in to comment.