summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorey Richardson <corey@octayn.net>2017-09-24 09:18:26 -0400
committerGraham Northup <grahamnorthup@yahoo.com>2017-09-24 19:01:22 -0400
commit150d71cae770598ade7e09419150f1218e961128 (patch)
treea1b0848642fa59f746d9e4587e585a22df0188e2
parent5f1e73ab5bd0709dd408064c06f2717182777537 (diff)
Fix more style things
All reported by clippy. Mostly stuff like unnecessary lifetimes or references.
-rw-r--r--src/lang/parser.rs14
-rw-r--r--src/lang/tokenizer.rs44
-rw-r--r--src/proto.rs1
-rw-r--r--src/synth/logic.rs8
-rw-r--r--src/synth/math.rs16
-rw-r--r--src/synth/mod.rs16
-rw-r--r--src/synth/noise.rs2
-rw-r--r--src/synth/param.rs2
-rw-r--r--src/synth/rel.rs20
-rw-r--r--src/synth/saw.rs4
-rw-r--r--src/synth/sine.rs4
-rw-r--r--src/synth/square.rs4
-rw-r--r--src/synth/triangle.rs4
13 files changed, 67 insertions, 72 deletions
diff --git a/src/lang/parser.rs b/src/lang/parser.rs
index 5264554..7419a56 100644
--- a/src/lang/parser.rs
+++ b/src/lang/parser.rs
@@ -24,10 +24,10 @@ impl ErrorType {
desc: "".to_string(),
};
- ret.desc = match &ret.kind {
- &ErrorKind::Unexpected(found, expected) => format!("Found {:?}, expected {:?}", found, expected),
- &ErrorKind::ExpectedOp(c, found) => format!("Expected {:?}, found {:?}", c, found),
- &ErrorKind::UnknownGen(ref s) => format!("Unknown generator name {}", s),
+ ret.desc = match ret.kind {
+ ErrorKind::Unexpected(found, expected) => format!("Found {:?}, expected {:?}", found, expected),
+ ErrorKind::ExpectedOp(c, found) => format!("Expected {:?}, found {:?}", c, found),
+ ErrorKind::UnknownGen(ref s) => format!("Unknown generator name {}", s),
};
ret
@@ -42,7 +42,7 @@ impl ErrorType {
}
impl Error for ErrorType {
- fn description<'a>(&'a self) -> &'a str {
+ fn description(&self) -> &str {
&self.desc
}
}
@@ -144,8 +144,8 @@ impl<T: Iterator<Item=char>> Parser<T> {
if self.expect_op('=').is_ok() {
nm
} else {
- match &self.token {
- &Token::Oper(c) if c == '(' => {
+ match self.token {
+ Token::Oper(c) if c == '(' => {
self.push_back(Token::Ident(nm));
ctr += 1;
(ctr - 1).to_string()
diff --git a/src/lang/tokenizer.rs b/src/lang/tokenizer.rs
index 9b408d2..74b304d 100644
--- a/src/lang/tokenizer.rs
+++ b/src/lang/tokenizer.rs
@@ -79,20 +79,20 @@ impl ErrorType {
desc: "".to_string(),
};
- ret.desc = match &ret.kind {
- &ErrorKind::UnexpectedEOF(ref loc) => format!("Unexpected EOF {}", match loc {
- &Location::InString => "in string constant",
- &Location::InStringEscape => "in string escape",
+ ret.desc = match ret.kind {
+ ErrorKind::UnexpectedEOF(ref loc) => format!("Unexpected EOF {}", match *loc {
+ Location::InString => "in string constant",
+ Location::InStringEscape => "in string escape",
}),
- &ErrorKind::BadEscapeValue(ref kind, ref val, ref err) => format!("Bad {} escape {}: {:?}", match kind {
- &EscapeKind::Hexadecimal => "hexadecimal",
- &EscapeKind::Octal => "octal",
+ ErrorKind::BadEscapeValue(ref kind, ref val, ref err) => format!("Bad {} escape {}: {:?}", match *kind {
+ EscapeKind::Hexadecimal => "hexadecimal",
+ EscapeKind::Octal => "octal",
}, val, err),
- &ErrorKind::BadNumericLiteral(ref kind, ref val, ref err) => format!("Bad {} literal {}: {:?}", match kind {
- &NumericKind::Integer => "integer",
- &NumericKind::Float => "floating point",
+ ErrorKind::BadNumericLiteral(ref kind, ref val, ref err) => format!("Bad {} literal {}: {:?}", match *kind {
+ NumericKind::Integer => "integer",
+ NumericKind::Float => "floating point",
}, val, err),
- &ErrorKind::UnknownChar(c) => format!("Unknown character {}", c),
+ ErrorKind::UnknownChar(c) => format!("Unknown character {}", c),
};
ret
@@ -107,22 +107,17 @@ impl ErrorType {
}
impl Error for ErrorType {
- fn description<'a>(&'a self) -> &'a str {
+ fn description(&self) -> &str {
&self.desc
}
fn cause(&self) -> Option<&Error> {
- match &self.kind {
- &ErrorKind::UnexpectedEOF(_) => None,
- &ErrorKind::BadEscapeValue(_, _, ref err) => match err {
- &Some(ref err) => Some(&**err),
- &None => None,
+ match self.kind {
+ ErrorKind::BadNumericLiteral(_, _, ref err) | ErrorKind::BadEscapeValue(_, _, ref err) => match *err {
+ Some(ref err) => Some(&**err),
+ None => None,
},
- &ErrorKind::BadNumericLiteral(_, _, ref err) => match err {
- &Some(ref err) => Some(&**err),
- &None => None,
- },
- &ErrorKind::UnknownChar(_) => None,
+ ErrorKind::UnexpectedEOF(_) | ErrorKind::UnknownChar(_) => None,
}
}
}
@@ -392,7 +387,7 @@ impl<T: Iterator<Item=char>> Tokenizer<T> {
}
/* Everything else */
- return Ok(Token::Oper(cc));
+ Ok(Token::Oper(cc))
}
}
@@ -401,8 +396,7 @@ impl<T: Iterator<Item=char>> Iterator for Tokenizer<T> {
fn next(&mut self) -> Option<Token> {
match self.next_token() {
- Err(_) => None,
- Ok(Token::EOF) => None,
+ Err(_) | Ok(Token::EOF) => None,
Ok(t) => Some(t),
}
}
diff --git a/src/proto.rs b/src/proto.rs
index 3ec0aeb..d27a293 100644
--- a/src/proto.rs
+++ b/src/proto.rs
@@ -4,6 +4,7 @@ use super::*;
use ::byteorder::{ByteOrder, NetworkEndian};
+#[allow(dead_code)]
const OBLIGATE_POLYPHONE: u32 = 0xffffffff;
pub enum Command {
diff --git a/src/synth/logic.rs b/src/synth/logic.rs
index 672cc78..d5f9401 100644
--- a/src/synth/logic.rs
+++ b/src/synth/logic.rs
@@ -57,7 +57,7 @@ impl Generator for IfElse {
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -67,9 +67,9 @@ pub struct IfElseFactory;
impl GeneratorFactory for IfElseFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
- let cond = params.remove_param("cond", 0)?.as_gen()?;
- let iftrue = params.remove_param("iftrue", 1)?.as_gen()?;
- let iffalse = params.remove_param("iffalse", 2)?.as_gen()?;
+ let cond = params.remove_param("cond", 0)?.into_gen()?;
+ let iftrue = params.remove_param("iftrue", 1)?.into_gen()?;
+ let iffalse = params.remove_param("iffalse", 2)?.into_gen()?;
let buf = SampleBuffer::new(cmp::max(cmp::max(cond.buffer().len(), iftrue.buffer().len()), iffalse.buffer().len()));
Ok(Box::new(IfElse { cond: cond, iftrue: iftrue, iffalse: iffalse, buf: buf }))
}
diff --git a/src/synth/math.rs b/src/synth/math.rs
index 2b81786..1889139 100644
--- a/src/synth/math.rs
+++ b/src/synth/math.rs
@@ -20,7 +20,7 @@ impl Generator for Add {
}
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -31,7 +31,7 @@ pub struct AddFactory;
impl GeneratorFactory for AddFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
Ok(Box::new(Add {
- terms: params.get_pos_params().into_iter().map(|x| x.as_gen()).collect::<Result<Vec<_>, _>>()?,
+ terms: params.get_pos_params().into_iter().map(|x| x.into_gen()).collect::<Result<Vec<_>, _>>()?,
buf: SampleBuffer::new(params.env.default_buffer_size),
}))
}
@@ -58,7 +58,7 @@ impl Generator for Mul {
}
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -69,7 +69,7 @@ pub struct MulFactory;
impl GeneratorFactory for MulFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
Ok(Box::new(Mul {
- factors: params.get_pos_params().into_iter().map(|x| x.as_gen()).collect::<Result<Vec<_>, _>>()?,
+ factors: params.get_pos_params().into_iter().map(|x| x.into_gen()).collect::<Result<Vec<_>, _>>()?,
buf: SampleBuffer::new(params.env.default_buffer_size),
}))
}
@@ -98,7 +98,7 @@ impl Generator for Negate {
}
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -108,7 +108,7 @@ pub struct NegateFactory;
impl GeneratorFactory for NegateFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
- let gen = params.remove_param("value", 0)?.as_gen()?;
+ let gen = params.remove_param("value", 0)?.into_gen()?;
let len = gen.buffer().len();
Ok(Box::new(Negate {
value: gen,
@@ -140,7 +140,7 @@ impl Generator for Reciprocate {
}
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -150,7 +150,7 @@ pub struct ReciprocateFactory;
impl GeneratorFactory for ReciprocateFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
- let gen = params.remove_param("value", 0)?.as_gen()?;
+ let gen = params.remove_param("value", 0)?.into_gen()?;
let len = gen.buffer().len();
Ok(Box::new(Reciprocate {
value: gen,
diff --git a/src/synth/mod.rs b/src/synth/mod.rs
index fb9714b..e8d1758 100644
--- a/src/synth/mod.rs
+++ b/src/synth/mod.rs
@@ -63,7 +63,7 @@ impl SampleBuffer {
self.samples.len()
}
- pub fn iter_mut<'a>(&'a mut self) -> slice::IterMut<'a, f32> {
+ pub fn iter_mut(&mut self) -> slice::IterMut<f32> {
self.samples.iter_mut()
}
@@ -160,7 +160,7 @@ impl IndexMut<usize> for SampleBuffer {
pub trait Generator : Debug {
fn eval<'a>(&'a mut self, params: &Parameters) -> &'a SampleBuffer;
- fn buffer<'a>(&'a self) -> &'a SampleBuffer;
+ fn buffer(&self) -> &SampleBuffer;
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer;
}
@@ -186,10 +186,10 @@ impl GenFactoryErrorType {
desc: "".to_string(),
};
- ret.desc = match &ret.kind {
- &GenFactoryError::MissingRequiredParam(ref name, pos) => format!("Needed a parameter named {} or at pos {}", name, pos),
- &GenFactoryError::CannotConvert(from, to) => format!("Cannot convert {:?} to {:?}", from, to),
- &GenFactoryError::BadType(ty) => format!("Bad parameter type {:?}", ty),
+ ret.desc = match ret.kind {
+ GenFactoryError::MissingRequiredParam(ref name, pos) => format!("Needed a parameter named {} or at pos {}", name, pos),
+ GenFactoryError::CannotConvert(from, to) => format!("Cannot convert {:?} to {:?}", from, to),
+ GenFactoryError::BadType(ty) => format!("Bad parameter type {:?}", ty),
};
ret
@@ -210,7 +210,7 @@ impl From<GenFactoryError> for GenFactoryErrorType {
}
impl Error for GenFactoryErrorType {
- fn description<'a>(&'a self) -> &'a str {
+ fn description(&self) -> &str {
&self.desc
}
}
@@ -279,7 +279,7 @@ impl ParamValue {
}
}
- pub fn as_gen(self) -> Result<GenBox, GenFactoryError> {
+ pub fn into_gen(self) -> Result<GenBox, GenFactoryError> {
match self {
ParamValue::Integer(v) => Ok(Box::new(self::param::Param { name : "_".to_string(), default: v as f32, buf: SampleBuffer::new(1) })),
ParamValue::Float(v) => Ok(Box::new(self::param::Param { name : "_".to_string(), default: v, buf: SampleBuffer::new(1) })),
diff --git a/src/synth/noise.rs b/src/synth/noise.rs
index f241beb..850b75b 100644
--- a/src/synth/noise.rs
+++ b/src/synth/noise.rs
@@ -19,7 +19,7 @@ impl Generator for Noise {
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
diff --git a/src/synth/param.rs b/src/synth/param.rs
index 859f789..b020574 100644
--- a/src/synth/param.rs
+++ b/src/synth/param.rs
@@ -12,7 +12,7 @@ impl Generator for Param {
self.buf.set(*params.vars.get(&self.name).unwrap_or(&self.default));
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
diff --git a/src/synth/rel.rs b/src/synth/rel.rs
index bb3cf1f..e3c4216 100644
--- a/src/synth/rel.rs
+++ b/src/synth/rel.rs
@@ -105,7 +105,7 @@ impl Generator for Rel {
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -115,18 +115,18 @@ pub struct RelFactory;
impl GeneratorFactory for RelFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
- let op = match params.get_req_param("rel", 1)? {
+ let op = match *params.get_req_param("rel", 1)? {
/* TODO
- &ParamValue::Integer(v) => v.into(),
- &ParamValue::Float(v) => (v as isize).into(),
+ ParamValue::Integer(v) => v.into(),
+ ParamValue::Float(v) => (v as isize).into(),
*/
- &ParamValue::Integer(_) => return Err(GenFactoryError::BadType(ParamKind::Integer)),
- &ParamValue::Float(_) => return Err(GenFactoryError::BadType(ParamKind::Float)),
- &ParamValue::String(ref v) => (&*v as &str).into(),
- &ParamValue::Generator(_) => return Err(GenFactoryError::BadType(ParamKind::Generator)),
+ ParamValue::Integer(_) => return Err(GenFactoryError::BadType(ParamKind::Integer)),
+ ParamValue::Float(_) => return Err(GenFactoryError::BadType(ParamKind::Float)),
+ ParamValue::String(ref v) => (&*v as &str).into(),
+ ParamValue::Generator(_) => return Err(GenFactoryError::BadType(ParamKind::Generator)),
};
- let left = params.remove_param("left", 0)?.as_gen()?;
- let right = params.remove_param("right", 2)?.as_gen()?;
+ let left = params.remove_param("left", 0)?.into_gen()?;
+ let right = params.remove_param("right", 2)?.into_gen()?;
let buf = SampleBuffer::new(cmp::max(left.buffer().len(), right.buffer().len()));
Ok(Box::new(Rel {
left: left,
diff --git a/src/synth/saw.rs b/src/synth/saw.rs
index b85794d..054b3c8 100644
--- a/src/synth/saw.rs
+++ b/src/synth/saw.rs
@@ -19,7 +19,7 @@ impl Generator for Saw {
self.phase = (self.phase + pvel * (self.buf.len() as f32)) % 1.0;
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -30,7 +30,7 @@ pub struct SawFactory;
impl GeneratorFactory for SawFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
Ok(Box::new(Saw {
- freq: params.remove_param("freq", 0)?.as_gen()?,
+ freq: params.remove_param("freq", 0)?.into_gen()?,
phase: params.get_param("phase", 1, &ParamValue::Float(0.0)).as_f32()?,
buf: SampleBuffer::new(params.env.default_buffer_size),
}))
diff --git a/src/synth/sine.rs b/src/synth/sine.rs
index 918261c..66f29ef 100644
--- a/src/synth/sine.rs
+++ b/src/synth/sine.rs
@@ -22,7 +22,7 @@ impl Generator for Sine {
self.phase = (self.phase + pvel * (self.buf.len() as f32)) % TAU;
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -33,7 +33,7 @@ pub struct SineFactory;
impl GeneratorFactory for SineFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
Ok(Box::new(Sine {
- freq: params.remove_param("freq", 0)?.as_gen()?,
+ freq: params.remove_param("freq", 0)?.into_gen()?,
phase: params.get_param("phase", 1, &ParamValue::Float(0.0)).as_f32()?,
buf: SampleBuffer::new(params.env.default_buffer_size),
}))
diff --git a/src/synth/square.rs b/src/synth/square.rs
index d207562..9b4374f 100644
--- a/src/synth/square.rs
+++ b/src/synth/square.rs
@@ -23,7 +23,7 @@ impl Generator for Square {
self.phase = (self.phase + pvel * (self.buf.len() as f32)) % 1.0;
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -34,7 +34,7 @@ pub struct SquareFactory;
impl GeneratorFactory for SquareFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
Ok(Box::new(Square {
- freq: params.remove_param("freq", 0)?.as_gen()?,
+ freq: params.remove_param("freq", 0)?.into_gen()?,
phase: params.get_param("phase", 1, &ParamValue::Float(0.0)).as_f32()?,
buf: SampleBuffer::new(params.env.default_buffer_size),
}))
diff --git a/src/synth/triangle.rs b/src/synth/triangle.rs
index 4f62e4c..19a2296 100644
--- a/src/synth/triangle.rs
+++ b/src/synth/triangle.rs
@@ -27,7 +27,7 @@ impl Generator for Triangle {
self.phase = (self.phase + pvel * (self.buf.len() as f32)) % 1.0;
&self.buf
}
- fn buffer<'a>(&'a self) -> &'a SampleBuffer { &self.buf }
+ fn buffer(&self) -> &SampleBuffer { &self.buf }
fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
mem::replace(&mut self.buf, buf)
}
@@ -38,7 +38,7 @@ pub struct TriangleFactory;
impl GeneratorFactory for TriangleFactory {
fn new(&self, params: &mut FactoryParameters) -> Result<GenBox, GenFactoryError> {
Ok(Box::new(Triangle {
- freq: params.remove_param("freq", 0)?.as_gen()?,
+ freq: params.remove_param("freq", 0)?.into_gen()?,
phase: params.get_param("phase", 1, &ParamValue::Float(0.0)).as_f32()?,
buf: SampleBuffer::new(params.env.default_buffer_size),
}))