rename signature_type to function_type, fix cargo warnings

This commit is contained in:
vms 2020-05-28 16:05:58 +03:00
parent 8b9d33c14c
commit c2f2a23c38
8 changed files with 23 additions and 23 deletions

View File

@ -51,7 +51,7 @@ pub struct Import<'input> {
pub name: &'input str,
/// The type signature.
pub signature_type: u32,
pub function_type: u32,
}
/// Represents an exported function signature.

View File

@ -304,12 +304,12 @@ fn imports<'input, E: ParseError<&'input [u8]>>(
for _ in 0..number_of_imports {
consume!((input, namespace) = string(input)?);
consume!((input, name) = string(input)?);
consume!((input, signature_type) = uleb(input)?);
consume!((input, function_type) = uleb(input)?);
imports.push(Import {
namespace,
name,
signature_type: signature_type as u32,
function_type: function_type as u32,
});
}
@ -495,7 +495,7 @@ fn interfaces<'input, E: ParseError<&'input [u8]>>(
/// imports: vec![Import {
/// namespace: "ab",
/// name: "c",
/// signature_type: 0,
/// function_type: 0,
/// }],
/// adapters: vec![Adapter {
/// function_type: 0,
@ -890,12 +890,12 @@ mod tests {
Import {
namespace: "a",
name: "b",
signature_type: 1,
function_type: 1,
},
Import {
namespace: "c",
name: "d",
signature_type: 2,
function_type: 2,
},
],
));
@ -968,7 +968,7 @@ mod tests {
imports: vec![Import {
namespace: "ab",
name: "c",
signature_type: 0,
function_type: 0,
}],
adapters: vec![Adapter {
function_type: 0,

View File

@ -477,7 +477,7 @@ impl<'a> Parse<'a> for Import<'a> {
let namespace = parser.parse()?;
let name = parser.parse()?;
let signature_type = parser.parens(|parser| {
let function_type = parser.parens(|parser| {
parser.parse::<keyword::func>()?;
parser.parens(|parser| {
@ -490,7 +490,7 @@ impl<'a> Parse<'a> for Import<'a> {
Ok(Import {
namespace,
name,
signature_type,
function_type,
})
}
}
@ -616,7 +616,7 @@ impl<'a> Parse<'a> for Interfaces<'a> {
/// imports: vec![Import {
/// namespace: "ns",
/// name: "foo",
/// signature_type: 0,
/// function_type: 0,
/// }],
/// adapters: vec![Adapter {
/// function_type: 0,
@ -907,7 +907,7 @@ mod tests {
let output = Interface::Import(Import {
namespace: "ns",
name: "foo",
signature_type: 0,
function_type: 0,
});
assert_eq!(parser::parse::<Interface>(&input).unwrap(), output);
@ -956,7 +956,7 @@ mod tests {
imports: vec![Import {
namespace: "ns",
name: "foo",
signature_type: 0,
function_type: 0,
}],
adapters: vec![Adapter {
function_type: 0,

View File

@ -190,7 +190,7 @@ where
fn to_bytes(&self, writer: &mut W) -> io::Result<()> {
self.namespace.to_bytes(writer)?;
self.name.to_bytes(writer)?;
(self.signature_type as u64).to_bytes(writer)?;
(self.function_type as u64).to_bytes(writer)?;
Ok(())
}
@ -556,7 +556,7 @@ mod tests {
Import {
namespace: "a",
name: "b",
signature_type: 0,
function_type: 0,
},
&[
0x01, // string of length 1
@ -594,7 +594,7 @@ mod tests {
imports: vec![Import {
namespace: "ab",
name: "c",
signature_type: 0,
function_type: 0,
}],
adapters: vec![Adapter {
function_type: 0,

View File

@ -18,7 +18,7 @@
//! imports: vec![Import {
//! namespace: "ns",
//! name: "foo",
//! signature_type: 0,
//! function_type: 0,
//! }],
//! adapters: vec![Adapter {
//! function_type: 0,
@ -207,7 +207,7 @@ impl<'input> ToString for &Import<'input> {
r#"(@interface import "{namespace}" "{name}" (func (type {type})))"#,
namespace = self.namespace,
name = self.name,
type = self.signature_type,
type = self.function_type,
)
}
}
@ -571,7 +571,7 @@ mod tests {
let input = (&Import {
namespace: "ns",
name: "foo",
signature_type: 0,
function_type: 0,
})
.to_string();
let output = r#"(@interface import "ns" "foo" (func (type 0)))"#;
@ -602,7 +602,7 @@ mod tests {
imports: vec![Import {
namespace: "ns",
name: "foo",
signature_type: 0,
function_type: 0,
}],
adapters: vec![Adapter {
function_type: 0,

View File

@ -44,7 +44,7 @@ executable_instruction!(
return Ok(())
}
if memory_view.len() <= pointer + length - 1 {
if memory_view.len() < pointer + length {
return Err(InstructionError::new(
instruction,
InstructionErrorKind::MemoryOutOfBoundsAccess {
@ -54,7 +54,7 @@ executable_instruction!(
));
}
let data: Vec<u8> = (&memory_view[pointer..=pointer + length - 1])
let data: Vec<u8> = (&memory_view[pointer..pointer + length])
.iter()
.map(Cell::get)
.collect();

View File

@ -33,7 +33,7 @@ where
/// Creates a new non-empty vector, based on an inner `Vec<T>`. If
/// the inner vector is empty, a `EmptyVec` error is returned.
pub fn new(items: Vec<T>) -> Result<Self, EmptyVec> {
if items.len() == 0 {
if items.is_empty() {
Err(EmptyVec)
} else {
Ok(Self(items))

View File

@ -23,7 +23,7 @@ fn test_binary_encoding_decoding_roundtrip() {
imports: vec![Import {
namespace: "a",
name: "b",
signature_type: 0,
function_type: 0,
}],
adapters: vec![Adapter {
function_type: 0,