#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2018::*;
#[macro_use]
extern crate std;
use miniconf::Miniconf;
struct Settings {
#[miniconf(defer)]
value: Option<u32>,
}
#[automatically_derived]
impl ::core::marker::Copy for Settings {}
#[automatically_derived]
impl ::core::clone::Clone for Settings {
#[inline]
fn clone(&self) -> Settings {
let _: ::core::clone::AssertParamIsClone<Option<u32>>;
*self
}
}
#[automatically_derived]
impl ::core::default::Default for Settings {
#[inline]
fn default() -> Settings {
Settings {
value: ::core::default::Default::default(),
}
}
}
impl miniconf::Miniconf for Settings {
fn string_set(
&mut self,
mut topic_parts: core::iter::Peekable<core::str::Split<char>>,
value: &[u8],
) -> Result<(), miniconf::Error> {
let field = topic_parts.next().ok_or(miniconf::Error::PathTooShort)?;
match field {
"value" => self.value.string_set(topic_parts, value),
_ => Err(miniconf::Error::PathNotFound),
}
}
fn string_get(
&self,
mut topic_parts: core::iter::Peekable<core::str::Split<char>>,
value: &mut [u8],
) -> Result<usize, miniconf::Error> {
let field = topic_parts.next().ok_or(miniconf::Error::PathTooShort)?;
match field {
"value" => self.value.string_get(topic_parts, value),
_ => Err(miniconf::Error::PathNotFound),
}
}
fn get_metadata(&self) -> miniconf::MiniconfMetadata {
let mut maximum_sizes = miniconf::MiniconfMetadata {
max_topic_size: 0,
max_depth: 0,
};
let mut index = 0;
loop {
let metadata = match index {
0usize => {
let mut meta = self.value.get_metadata();
if meta.max_topic_size > 0 {
meta.max_topic_size += 1;
}
meta.max_topic_size += "value".len();
meta
}
_ => break,
};
maximum_sizes
.max_topic_size = core::cmp::max(
maximum_sizes.max_topic_size,
metadata.max_topic_size,
);
maximum_sizes
.max_depth = core::cmp::max(maximum_sizes.max_depth, metadata.max_depth);
index += 1;
}
maximum_sizes.max_depth += 1;
maximum_sizes
}
fn recurse_paths<const TS: usize>(
&self,
index: &mut [usize],
topic: &mut miniconf::heapless::String<TS>,
) -> Option<()> {
if index.len() == 0 {
::core::panicking::unreachable_display(&"Index stack too small");
}
loop {
match index[0] {
0usize => {
let original_length = topic.len();
let postfix = if topic.len() != 0 { "/value" } else { "value" };
if topic.push_str(postfix).is_err() {
::core::panicking::unreachable_display(
&"Topic buffer too short",
);
}
if self.value.recurse_paths(&mut index[1..], topic).is_some() {
return Some(());
}
topic.truncate(original_length);
index[0] += 1;
index[1..].iter_mut().for_each(|x| *x = 0);
}
_ => return None,
};
}
}
}
extern crate test;
#[cfg(test)]
#[rustc_test_marker]
pub const get_set_none: test::TestDescAndFn = test::TestDescAndFn {
desc: test::TestDesc {
name: test::StaticTestName("get_set_none"),
ignore: false,
ignore_message: ::core::option::Option::None,
compile_fail: false,
no_run: false,
should_panic: test::ShouldPanic::No,
test_type: test::TestType::IntegrationTest,
},
testfn: test::StaticTestFn(|| test::assert_test_result(get_set_none())),
};
fn get_set_none() {
let mut settings = Settings::default();
let mut data = [0; 100];
settings.value.take();
if !settings.get("value", &mut data).is_err() {
::core::panicking::panic(
"assertion failed: settings.get(\\\"value\\\", &mut data).is_err()",
)
}
if !settings.set("value", b"5").is_err() {
::core::panicking::panic(
"assertion failed: settings.set(\\\"value\\\", b\\\"5\\\").is_err()",
)
}
}
extern crate test;
#[cfg(test)]
#[rustc_test_marker]
pub const get_set_some: test::TestDescAndFn = test::TestDescAndFn {
desc: test::TestDesc {
name: test::StaticTestName("get_set_some"),
ignore: false,
ignore_message: ::core::option::Option::None,
compile_fail: false,
no_run: false,
should_panic: test::ShouldPanic::No,
test_type: test::TestType::IntegrationTest,
},
testfn: test::StaticTestFn(|| test::assert_test_result(get_set_some())),
};
fn get_set_some() {
let mut settings = Settings::default();
let mut data = [0; 10];
settings.value.replace(5);
let len = settings.get("value", &mut data).unwrap();
match (&&data[..len], &b"5") {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(
kind,
&*left_val,
&*right_val,
::core::option::Option::None,
);
}
}
};
settings.set("value", b"7").unwrap();
match (&settings.value.unwrap(), &7) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(
kind,
&*left_val,
&*right_val,
::core::option::Option::None,
);
}
}
};
}
extern crate test;
#[cfg(test)]
#[rustc_test_marker]
pub const iterate_some_none: test::TestDescAndFn = test::TestDescAndFn {
desc: test::TestDesc {
name: test::StaticTestName("iterate_some_none"),
ignore: false,
ignore_message: ::core::option::Option::None,
compile_fail: false,
no_run: false,
should_panic: test::ShouldPanic::No,
test_type: test::TestType::IntegrationTest,
},
testfn: test::StaticTestFn(|| test::assert_test_result(iterate_some_none())),
};
fn iterate_some_none() {
let mut settings = Settings::default();
let mut state = [0; 10];
settings.value.take();
let mut iterator = settings.iter_settings::<128>(&mut state).unwrap();
if !iterator.next().is_none() {
::core::panicking::panic("assertion failed: iterator.next().is_none()")
}
let mut state = [0; 10];
settings.value.replace(5);
let mut iterator = settings.iter_settings::<128>(&mut state).unwrap();
match (&iterator.next().unwrap(), &"value") {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(
kind,
&*left_val,
&*right_val,
::core::option::Option::None,
);
}
}
};
}
#[rustc_main]
pub fn main() -> () {
extern crate test;
test::test_main_static(&[&get_set_none, &get_set_some, &iterate_some_none])
}