2017-06-08 18:39:13 +00:00
|
|
|
#[cfg(feature = "yaml")]
|
2016-12-29 02:14:11 +00:00
|
|
|
macro_rules! yaml_tuple2 {
|
|
|
|
($a:ident, $v:ident, $c:ident) => {{
|
2018-08-02 03:13:51 +00:00
|
|
|
if let Some(vec) = $v.as_vec() {
|
|
|
|
for ys in vec {
|
|
|
|
if let Some(tup) = ys.as_vec() {
|
|
|
|
debug_assert_eq!(2, tup.len());
|
|
|
|
$a = $a.$c(yaml_str!(tup[0]), yaml_str!(tup[1]));
|
|
|
|
} else {
|
|
|
|
panic!("Failed to convert YAML value to vec");
|
2016-12-29 02:14:11 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-02 03:13:51 +00:00
|
|
|
} else {
|
|
|
|
panic!("Failed to convert YAML value to vec");
|
2016-12-29 02:14:11 +00:00
|
|
|
}
|
2018-08-02 03:13:51 +00:00
|
|
|
$a
|
|
|
|
}};
|
2016-12-29 02:14:11 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 18:39:13 +00:00
|
|
|
#[cfg(feature = "yaml")]
|
2016-12-29 02:14:11 +00:00
|
|
|
macro_rules! yaml_tuple3 {
|
|
|
|
($a:ident, $v:ident, $c:ident) => {{
|
2018-08-02 03:13:51 +00:00
|
|
|
if let Some(vec) = $v.as_vec() {
|
|
|
|
for ys in vec {
|
|
|
|
if let Some(tup) = ys.as_vec() {
|
|
|
|
debug_assert_eq!(3, tup.len());
|
|
|
|
$a = $a.$c(yaml_str!(tup[0]), yaml_opt_str!(tup[1]), yaml_str!(tup[2]));
|
|
|
|
} else {
|
|
|
|
panic!("Failed to convert YAML value to vec");
|
2016-12-29 02:14:11 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-02 03:13:51 +00:00
|
|
|
} else {
|
|
|
|
panic!("Failed to convert YAML value to vec");
|
2016-12-29 02:14:11 +00:00
|
|
|
}
|
2018-08-02 03:13:51 +00:00
|
|
|
$a
|
|
|
|
}};
|
2016-12-29 02:14:11 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 18:39:13 +00:00
|
|
|
#[cfg(feature = "yaml")]
|
2016-08-28 03:42:31 +00:00
|
|
|
macro_rules! yaml_vec_or_str {
|
|
|
|
($v:ident, $a:ident, $c:ident) => {{
|
2018-08-02 03:13:51 +00:00
|
|
|
let maybe_vec = $v.as_vec();
|
|
|
|
if let Some(vec) = maybe_vec {
|
|
|
|
for ys in vec {
|
|
|
|
if let Some(s) = ys.as_str() {
|
2016-08-28 03:42:31 +00:00
|
|
|
$a = $a.$c(s);
|
|
|
|
} else {
|
2018-08-02 03:13:51 +00:00
|
|
|
panic!("Failed to convert YAML value {:?} to a string", ys);
|
2016-08-28 03:42:31 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-02 03:13:51 +00:00
|
|
|
} else {
|
|
|
|
if let Some(s) = $v.as_str() {
|
|
|
|
$a = $a.$c(s);
|
|
|
|
} else {
|
|
|
|
panic!(
|
|
|
|
"Failed to convert YAML value {:?} to either a vec or string",
|
|
|
|
$v
|
|
|
|
);
|
|
|
|
}
|
2016-08-28 03:42:31 +00:00
|
|
|
}
|
2018-08-02 03:13:51 +00:00
|
|
|
$a
|
|
|
|
}};
|
2016-08-28 03:42:31 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 18:39:13 +00:00
|
|
|
#[cfg(feature = "yaml")]
|
2016-12-29 02:14:11 +00:00
|
|
|
macro_rules! yaml_opt_str {
|
|
|
|
($v:expr) => {{
|
|
|
|
if $v.is_null() {
|
2018-08-02 03:13:51 +00:00
|
|
|
Some(
|
|
|
|
$v.as_str()
|
|
|
|
.unwrap_or_else(|| panic!("failed to convert YAML {:?} value to a string", $v)),
|
|
|
|
)
|
2016-12-29 02:14:11 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2018-11-05 00:44:28 +00:00
|
|
|
#[cfg(feature = "yaml")]
|
|
|
|
macro_rules! yaml_char {
|
|
|
|
($v:expr) => {{
|
|
|
|
$v.as_str()
|
|
|
|
.unwrap_or_else(|| panic!("failed to convert YAML {:?} value to a string", $v))
|
|
|
|
.chars()
|
|
|
|
.next()
|
|
|
|
.unwrap_or_else(|| panic!("Expected char"))
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2017-06-08 18:39:13 +00:00
|
|
|
#[cfg(feature = "yaml")]
|
2016-12-29 02:14:11 +00:00
|
|
|
macro_rules! yaml_str {
|
|
|
|
($v:expr) => {{
|
2018-08-02 03:13:51 +00:00
|
|
|
$v.as_str()
|
|
|
|
.unwrap_or_else(|| panic!("failed to convert YAML {:?} value to a string", $v))
|
2016-12-29 02:14:11 +00:00
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2018-11-05 00:44:28 +00:00
|
|
|
#[cfg(feature = "yaml")]
|
|
|
|
macro_rules! yaml_to_char {
|
|
|
|
($a:ident, $v:ident, $c:ident) => {{
|
|
|
|
$a.$c(yaml_char!($v))
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2017-06-08 18:39:13 +00:00
|
|
|
#[cfg(feature = "yaml")]
|
2016-08-28 03:42:31 +00:00
|
|
|
macro_rules! yaml_to_str {
|
|
|
|
($a:ident, $v:ident, $c:ident) => {{
|
2016-12-29 02:14:11 +00:00
|
|
|
$a.$c(yaml_str!($v))
|
2016-08-28 03:42:31 +00:00
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2017-06-08 18:39:13 +00:00
|
|
|
#[cfg(feature = "yaml")]
|
2016-08-28 03:42:31 +00:00
|
|
|
macro_rules! yaml_to_bool {
|
|
|
|
($a:ident, $v:ident, $c:ident) => {{
|
2018-08-02 03:13:51 +00:00
|
|
|
$a.$c($v
|
|
|
|
.as_bool()
|
|
|
|
.unwrap_or_else(|| panic!("failed to convert YAML {:?} value to a string", $v)))
|
2016-08-28 03:42:31 +00:00
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2017-06-08 18:39:13 +00:00
|
|
|
#[cfg(feature = "yaml")]
|
2016-08-28 03:42:31 +00:00
|
|
|
macro_rules! yaml_to_u64 {
|
|
|
|
($a:ident, $v:ident, $c:ident) => {{
|
2018-08-02 03:13:51 +00:00
|
|
|
$a.$c($v
|
|
|
|
.as_i64()
|
|
|
|
.unwrap_or_else(|| panic!("failed to convert YAML {:?} value to a string", $v))
|
|
|
|
as u64)
|
2016-08-28 03:42:31 +00:00
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2017-06-08 18:39:13 +00:00
|
|
|
#[cfg(feature = "yaml")]
|
2016-08-28 03:42:31 +00:00
|
|
|
macro_rules! yaml_to_usize {
|
|
|
|
($a:ident, $v:ident, $c:ident) => {{
|
2018-08-02 03:13:51 +00:00
|
|
|
$a.$c($v
|
|
|
|
.as_i64()
|
|
|
|
.unwrap_or_else(|| panic!("failed to convert YAML {:?} value to a string", $v))
|
|
|
|
as usize)
|
2016-08-28 03:42:31 +00:00
|
|
|
}};
|
|
|
|
}
|