Lint for the clippy gods in the edn crate (#340)
Signed-off-by: Victor Porof <victor.porof@gmail.com>
This commit is contained in:
parent
0d3b8e4b29
commit
bf707acbc3
3 changed files with 20 additions and 21 deletions
|
@ -38,12 +38,10 @@ impl Value {
|
||||||
/// 2,
|
/// 2,
|
||||||
/// 3].
|
/// 3].
|
||||||
fn bracket<'a, A, T, I>(&'a self, allocator: &'a A, open: T, vs: I, close: T) -> pretty::DocBuilder<'a, A>
|
fn bracket<'a, A, T, I>(&'a self, allocator: &'a A, open: T, vs: I, close: T) -> pretty::DocBuilder<'a, A>
|
||||||
where A: pretty::DocAllocator<'a>, T: Into<Cow<'a, str>>,
|
where A: pretty::DocAllocator<'a>, T: Into<Cow<'a, str>>, I: IntoIterator<Item=&'a Value> {
|
||||||
I: IntoIterator<Item=&'a Value>,
|
|
||||||
{
|
|
||||||
let open = open.into();
|
let open = open.into();
|
||||||
let n = open.len();
|
let n = open.len();
|
||||||
let i = vs.into_iter().map(|ref v| v.as_doc(allocator)).intersperse(allocator.space());
|
let i = vs.into_iter().map(|v| v.as_doc(allocator)).intersperse(allocator.space());
|
||||||
allocator.text(open)
|
allocator.text(open)
|
||||||
.append(allocator.concat(i).nest(n))
|
.append(allocator.concat(i).nest(n))
|
||||||
.append(allocator.text(close))
|
.append(allocator.text(close))
|
||||||
|
@ -55,22 +53,22 @@ impl Value {
|
||||||
/// readability and limited whitespace expansion.
|
/// readability and limited whitespace expansion.
|
||||||
pub fn as_doc<'a, A>(&'a self, pp: &'a A) -> pretty::DocBuilder<'a, A>
|
pub fn as_doc<'a, A>(&'a self, pp: &'a A) -> pretty::DocBuilder<'a, A>
|
||||||
where A: pretty::DocAllocator<'a> {
|
where A: pretty::DocAllocator<'a> {
|
||||||
match self {
|
match *self {
|
||||||
&Value::Vector(ref vs) => self.bracket(pp, "[", vs, "]"),
|
Value::Vector(ref vs) => self.bracket(pp, "[", vs, "]"),
|
||||||
&Value::List(ref vs) => self.bracket(pp, "(", vs, ")"),
|
Value::List(ref vs) => self.bracket(pp, "(", vs, ")"),
|
||||||
&Value::Set(ref vs) => self.bracket(pp, "#{", vs, "}"),
|
Value::Set(ref vs) => self.bracket(pp, "#{", vs, "}"),
|
||||||
&Value::Map(ref vs) => {
|
Value::Map(ref vs) => {
|
||||||
let xs = vs.iter().rev().map(|(ref k, ref v)| k.as_doc(pp).append(pp.space()).append(v.as_doc(pp)).group()).intersperse(pp.space());
|
let xs = vs.iter().rev().map(|(k, v)| k.as_doc(pp).append(pp.space()).append(v.as_doc(pp)).group()).intersperse(pp.space());
|
||||||
pp.text("{")
|
pp.text("{")
|
||||||
.append(pp.concat(xs).nest(1))
|
.append(pp.concat(xs).nest(1))
|
||||||
.append(pp.text("}"))
|
.append(pp.text("}"))
|
||||||
.group()
|
.group()
|
||||||
}
|
}
|
||||||
&Value::NamespacedSymbol(ref v) => pp.text(v.namespace.as_ref()).append("/").append(v.name.as_ref()),
|
Value::NamespacedSymbol(ref v) => pp.text(v.namespace.as_ref()).append("/").append(v.name.as_ref()),
|
||||||
&Value::PlainSymbol(ref v) => pp.text(v.0.as_ref()),
|
Value::PlainSymbol(ref v) => pp.text(v.0.as_ref()),
|
||||||
&Value::NamespacedKeyword(ref v) => pp.text(":").append(v.namespace.as_ref()).append("/").append(v.name.as_ref()),
|
Value::NamespacedKeyword(ref v) => pp.text(":").append(v.namespace.as_ref()).append("/").append(v.name.as_ref()),
|
||||||
&Value::Keyword(ref v) => pp.text(":").append(v.0.as_ref()),
|
Value::Keyword(ref v) => pp.text(":").append(v.0.as_ref()),
|
||||||
&Value::Text(ref v) => pp.text("\"").append(v.as_ref()).append("\""),
|
Value::Text(ref v) => pp.text("\"").append(v.as_ref()).append("\""),
|
||||||
_ => pp.text(self.to_string())
|
_ => pp.text(self.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,8 +45,8 @@ pub enum Value {
|
||||||
Map(BTreeMap<Value, Value>),
|
Map(BTreeMap<Value, Value>),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SpannedValue is the parallel to Value but used in ValueAndSpan.
|
/// `SpannedValue` is the parallel to `Value` but used in `ValueAndSpan`.
|
||||||
/// Container types have ValueAndSpan children.
|
/// Container types have `ValueAndSpan` children.
|
||||||
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
|
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
|
||||||
pub enum SpannedValue {
|
pub enum SpannedValue {
|
||||||
Nil,
|
Nil,
|
||||||
|
@ -69,7 +69,7 @@ pub enum SpannedValue {
|
||||||
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
|
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
|
||||||
pub struct Span(pub usize, pub usize);
|
pub struct Span(pub usize, pub usize);
|
||||||
|
|
||||||
/// A wrapper type around SpannedValue and Span, representing some EDN Value
|
/// A wrapper type around `SpannedValue` and `Span`, representing some EDN value
|
||||||
/// and the parsing offset (start, end) in the original EDN string.
|
/// and the parsing offset (start, end) in the original EDN string.
|
||||||
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
|
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
|
||||||
pub struct ValueAndSpan {
|
pub struct ValueAndSpan {
|
||||||
|
@ -113,9 +113,9 @@ macro_rules! def_from {
|
||||||
/// like `from_bigint()` where the conversion is optional.
|
/// like `from_bigint()` where the conversion is optional.
|
||||||
macro_rules! def_from_option {
|
macro_rules! def_from_option {
|
||||||
($name: ident, $out: ty, $kind: path, $t: ty, $( $transform: expr ),* ) => {
|
($name: ident, $out: ty, $kind: path, $t: ty, $( $transform: expr ),* ) => {
|
||||||
pub fn $name<'a>(src: $t) -> Option<$out> {
|
pub fn $name(src: $t) -> Option<$out> {
|
||||||
$( let src = $transform(src); )*
|
$( let src = $transform(src); )*
|
||||||
src.map(|v| $kind(v))
|
src.map($kind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,7 +277,7 @@ macro_rules! def_common_value_methods {
|
||||||
def_into!(into_set, $t::Set, BTreeSet<$tchild>,);
|
def_into!(into_set, $t::Set, BTreeSet<$tchild>,);
|
||||||
def_into!(into_map, $t::Map, BTreeMap<$tchild, $tchild>,);
|
def_into!(into_map, $t::Map, BTreeMap<$tchild, $tchild>,);
|
||||||
|
|
||||||
def_from_option!(from_bigint, $t, $t::BigInteger, &'a str, |src: &'a str| src.parse::<BigInt>().ok());
|
def_from_option!(from_bigint, $t, $t::BigInteger, &str, |src: &str| src.parse::<BigInt>().ok());
|
||||||
def_from!(from_float, $t, $t::Float, f64, |src: f64| OrderedFloat::from(src));
|
def_from!(from_float, $t, $t::Float, f64, |src: f64| OrderedFloat::from(src));
|
||||||
def_from!(from_ordered_float, $t, $t::Float, OrderedFloat<f64>,);
|
def_from!(from_ordered_float, $t, $t::Float, OrderedFloat<f64>,);
|
||||||
|
|
||||||
|
|
|
@ -1348,6 +1348,7 @@ macro_rules! def_test_into_type {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg_attr(feature = "cargo-clippy", allow(float_cmp))]
|
||||||
fn test_is_and_as_type_helper_functions() {
|
fn test_is_and_as_type_helper_functions() {
|
||||||
let max_i64 = i64::max_value().to_bigint().unwrap();
|
let max_i64 = i64::max_value().to_bigint().unwrap();
|
||||||
let bigger = &max_i64 * &max_i64;
|
let bigger = &max_i64 * &max_i64;
|
||||||
|
|
Loading…
Reference in a new issue