Test showing surprising inference of the unit type.
This commit is contained in:
commit
33bf1dc1b3
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
||||
71
Cargo.lock
generated
Normal file
71
Cargo.lock
generated
Normal file
@ -0,0 +1,71 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustinferencetest"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.123"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae"
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.123"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.60"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "rustinferencetest"
|
||||
version = "0.1.0"
|
||||
authors = ["Bill Thiede <git@xinu.tv>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serde = "1"
|
||||
serde_derive = "1"
|
||||
toml = "0.5.8"
|
||||
19
default.nix
Normal file
19
default.nix
Normal file
@ -0,0 +1,19 @@
|
||||
let
|
||||
unstableTarball = fetchTarball
|
||||
"https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz";
|
||||
pkgs = import <nixpkgs> { };
|
||||
unstable = import unstableTarball { };
|
||||
|
||||
in with pkgs;
|
||||
pkgs.mkShell {
|
||||
name = "rust";
|
||||
buildInputs = [
|
||||
openssl
|
||||
pkg-config
|
||||
unstable.cargo
|
||||
unstable.rustc
|
||||
unstable.rustfmt
|
||||
unstable.rust-analyzer
|
||||
postgresql
|
||||
];
|
||||
}
|
||||
51
src/main.rs
Normal file
51
src/main.rs
Normal file
@ -0,0 +1,51 @@
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct Config {
|
||||
sites: HashMap<String, Site>,
|
||||
}
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct Site {
|
||||
url: String,
|
||||
title: String,
|
||||
hover: Option<String>,
|
||||
main_image: String,
|
||||
alternate_image: Option<String>,
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<std::error::Error>> {
|
||||
let c = Config {
|
||||
sites: vec![
|
||||
(
|
||||
"xkcd".to_string(),
|
||||
Site {
|
||||
url: "https://xkcd.com/1/".to_string(),
|
||||
title: "title".to_string(),
|
||||
hover: None,
|
||||
main_image: "img".to_string(),
|
||||
alternate_image: None,
|
||||
},
|
||||
),
|
||||
(
|
||||
"sinfest".to_string(),
|
||||
Site {
|
||||
url: "https://sinfest.net/view.php?date=2000-01-17".to_string(),
|
||||
title: "title".to_string(),
|
||||
hover: None,
|
||||
main_image: "img".to_string(),
|
||||
alternate_image: None,
|
||||
},
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
};
|
||||
let s = toml::to_string(&c)?;
|
||||
println!("s {}", s);
|
||||
// c is inferred as the unit type judging by the error you get when you print with Display
|
||||
// formatting (i.e. "{}") instead of debug formating (i.e. "{:?}").
|
||||
let c = toml::from_str(&s)?;
|
||||
println!("c {:?}", c);
|
||||
Ok(())
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user