Created
January 8, 2018 16:20
-
-
Save hanepjiv/5ad9dfad52e57d34bbea82e021222583 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -*- mode:rust; coding:utf-8-unix; -*- | |
//! bincode.rs | |
// Copyright 2017 hanepjiv | |
// @author hanepjiv <hanepjiv@gmail.com> | |
// @copyright The MIT License (MIT) / Apache License Version 2.0 | |
// @since 2018/01/09 | |
// @date 2018/01/09 | |
// //////////////////////////////////////////////////////////////////////////// | |
// attribute ================================================================= | |
#![deny(anonymous_parameters, box_pointers, missing_copy_implementations, | |
missing_debug_implementations, missing_docs, trivial_casts, | |
trivial_numeric_casts, unsafe_code, unused_extern_crates, | |
unstable_features, unused_import_braces, unused_qualifications, | |
unused_results, variant_size_differences, const_err, dead_code, | |
deprecated, illegal_floating_point_literal_pattern, improper_ctypes, | |
late_bound_lifetime_arguments, non_camel_case_types, | |
non_shorthand_field_patterns, non_snake_case, non_upper_case_globals, | |
no_mangle_generic_items, overflowing_literals, path_statements, | |
patterns_in_fns_without_body, plugin_as_library, private_in_public, | |
private_no_mangle_fns, private_no_mangle_statics, | |
renamed_and_removed_lints, stable_features, unconditional_recursion, | |
unions_with_drop_fields, unknown_lints, unreachable_code, | |
unreachable_patterns, unused_allocation, unused_assignments, | |
unused_attributes, unused_comparisons, unused_doc_comment, | |
unused_features, unused_imports, unused_macros, unused_must_use, | |
unused_mut, unused_parens, unused_unsafe, unused_variables, | |
while_true)] | |
#![warn(dead_code)] | |
#![allow(box_pointers, unsafe_code, trivial_casts, trivial_numeric_casts)] | |
// extern ==================================================================== | |
extern crate bincode; | |
// use ======================================================================= | |
// //////////////////////////////////////////////////////////////////////////// | |
// ============================================================================ | |
fn app() -> ::std::result::Result<(), Box<::std::error::Error>> { | |
let x = (0i32, 1i32, None, Some(1i32)); | |
let dump = ::bincode::serialize(&x, ::bincode::Infinite)?; | |
let y = | |
::bincode::deserialize::<(i32, i32, Option<i32>, Option<i32>)>(&dump)?; | |
assert_eq!(x, y); | |
Ok(println!("{:?} => {:?} => {:?}", x, dump, y)) | |
// (0, 1, None, Some(1)) => [0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0] => (0, 1, None, Some(1)) | |
// | |
// 0i32 => [0, 0, 0, 0] | |
// 1i32 => [1, 0, 0, 0] | |
// None => [0] | |
// Some(1i32) => [1, 1, 0, 0, 0] | |
} | |
// ============================================================================ | |
fn main() { | |
if let Err(x) = app() { | |
eprintln!("{:?}", x); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment