mirror of
https://github.com/fluencelabs/marine-rs-sdk-test
synced 2024-12-04 15:20:18 +00:00
move to new alloc features, apply rust 2018 idioms
This commit is contained in:
parent
8ca4b17ff9
commit
ac00542974
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
# Rust artifacts
|
||||
target
|
||||
Cargo.lock
|
||||
|
||||
# IDE metadate
|
||||
|
@ -85,9 +85,9 @@
|
||||
unused_unsafe,
|
||||
unreachable_patterns
|
||||
)]
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![recursion_limit = "128"]
|
||||
|
||||
extern crate proc_macro;
|
||||
mod macro_attr_parser;
|
||||
mod macro_input_parser;
|
||||
|
||||
|
@ -28,7 +28,7 @@ pub enum HandlerAttr {
|
||||
}
|
||||
|
||||
impl HandlerAttrs {
|
||||
pub fn init_fn_name(&self) -> Option<(&str)> {
|
||||
pub fn init_fn_name(&self) -> Option<&str> {
|
||||
self.handler_attrs
|
||||
.iter()
|
||||
.filter_map(|attr| match attr {
|
||||
@ -38,7 +38,7 @@ impl HandlerAttrs {
|
||||
.next()
|
||||
}
|
||||
|
||||
pub fn side_modules(&self) -> Option<(&Vec<String>)> {
|
||||
pub fn side_modules(&self) -> Option<&Vec<String>> {
|
||||
self.handler_attrs
|
||||
.iter()
|
||||
.filter_map(|attr| match attr {
|
||||
@ -58,7 +58,7 @@ impl Default for HandlerAttrs {
|
||||
}
|
||||
|
||||
impl Parse for HandlerAttrs {
|
||||
fn parse(input: ParseStream) -> syn::Result<Self> {
|
||||
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
|
||||
let mut attrs = HandlerAttrs::default();
|
||||
if input.is_empty() {
|
||||
return Ok(attrs);
|
||||
@ -73,7 +73,7 @@ impl Parse for HandlerAttrs {
|
||||
}
|
||||
|
||||
impl Parse for HandlerAttr {
|
||||
fn parse(input: ParseStream) -> syn::Result<Self> {
|
||||
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
|
||||
// trying to parse the `init_fn`/`side_modules`/... tokens
|
||||
let attr_name = input.step(|cursor| match cursor.ident() {
|
||||
Some((ident, rem)) => Ok((ident, rem)),
|
||||
|
@ -19,12 +19,12 @@ path = "src/lib.rs"
|
||||
crate-type = ["rlib"]
|
||||
|
||||
[dependencies]
|
||||
log = { version = "0.4", features = ["std"] }
|
||||
syn = { version = '0.15.0', features = ['full'] }
|
||||
log = { version = "0.4.8", features = ["std"] }
|
||||
syn = { version = '0.15.44', features = ['full'] }
|
||||
|
||||
[dev-dependencies]
|
||||
simple_logger = "1.0" # used in doc test
|
||||
lazy_static = "1.3.0" # used in doc test
|
||||
simple_logger = "1.6.0" # used in doc test
|
||||
lazy_static = "1.4.0" # used in doc test
|
||||
|
||||
[features]
|
||||
# Turn on the Wasm logger.
|
||||
|
@ -29,8 +29,7 @@
|
||||
unused_unsafe,
|
||||
unreachable_patterns
|
||||
)]
|
||||
|
||||
extern crate core;
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
||||
pub mod memory;
|
||||
|
||||
|
@ -26,7 +26,7 @@ use std::io;
|
||||
pub struct MemError(String);
|
||||
|
||||
impl Display for MemError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
write!(f, "MemError({:?})", self)
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
pub mod errors;
|
||||
|
||||
use self::errors::MemError;
|
||||
use std::alloc::{Alloc, Global, Layout};
|
||||
use std::alloc::{alloc as global_alloc, dealloc as global_dealloc, Layout};
|
||||
use std::mem;
|
||||
use std::num::NonZeroUsize;
|
||||
use std::ptr::{self, NonNull};
|
||||
@ -43,7 +43,7 @@ pub const RESPONSE_SIZE_BYTES: usize = 4;
|
||||
///
|
||||
pub unsafe fn alloc(size: NonZeroUsize) -> MemResult<NonNull<u8>> {
|
||||
let layout: Layout = Layout::from_size_align(size.get(), mem::align_of::<u8>())?;
|
||||
Global.alloc(layout).map_err(Into::into)
|
||||
Ok(NonNull::new_unchecked(global_alloc(layout)))
|
||||
}
|
||||
|
||||
/// Deallocates memory area for current memory pointer and size. Actually is just a wrapper for
|
||||
@ -57,7 +57,7 @@ pub unsafe fn alloc(size: NonZeroUsize) -> MemResult<NonNull<u8>> {
|
||||
///
|
||||
pub unsafe fn dealloc(ptr: NonNull<u8>, size: NonZeroUsize) -> MemResult<()> {
|
||||
let layout = Layout::from_size_align(size.get(), mem::align_of::<u8>())?;
|
||||
Global.dealloc(ptr, layout);
|
||||
global_dealloc(ptr.as_ptr(), layout);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
unused_unsafe,
|
||||
unreachable_patterns
|
||||
)]
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
||||
extern crate fluence_sdk_macro;
|
||||
extern crate fluence_sdk_main;
|
||||
|
Loading…
Reference in New Issue
Block a user