mirror of
https://github.com/fluencelabs/marine-rs-sdk
synced 2025-03-15 14:30:48 +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
|
Cargo.lock
|
||||||
|
|
||||||
# IDE metadate
|
# IDE metadate
|
||||||
|
@ -85,9 +85,9 @@
|
|||||||
unused_unsafe,
|
unused_unsafe,
|
||||||
unreachable_patterns
|
unreachable_patterns
|
||||||
)]
|
)]
|
||||||
|
#![warn(rust_2018_idioms)]
|
||||||
#![recursion_limit = "128"]
|
#![recursion_limit = "128"]
|
||||||
|
|
||||||
extern crate proc_macro;
|
|
||||||
mod macro_attr_parser;
|
mod macro_attr_parser;
|
||||||
mod macro_input_parser;
|
mod macro_input_parser;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ pub enum HandlerAttr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HandlerAttrs {
|
impl HandlerAttrs {
|
||||||
pub fn init_fn_name(&self) -> Option<(&str)> {
|
pub fn init_fn_name(&self) -> Option<&str> {
|
||||||
self.handler_attrs
|
self.handler_attrs
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|attr| match attr {
|
.filter_map(|attr| match attr {
|
||||||
@ -38,7 +38,7 @@ impl HandlerAttrs {
|
|||||||
.next()
|
.next()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn side_modules(&self) -> Option<(&Vec<String>)> {
|
pub fn side_modules(&self) -> Option<&Vec<String>> {
|
||||||
self.handler_attrs
|
self.handler_attrs
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|attr| match attr {
|
.filter_map(|attr| match attr {
|
||||||
@ -58,7 +58,7 @@ impl Default for HandlerAttrs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Parse 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();
|
let mut attrs = HandlerAttrs::default();
|
||||||
if input.is_empty() {
|
if input.is_empty() {
|
||||||
return Ok(attrs);
|
return Ok(attrs);
|
||||||
@ -73,7 +73,7 @@ impl Parse for HandlerAttrs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for HandlerAttr {
|
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
|
// trying to parse the `init_fn`/`side_modules`/... tokens
|
||||||
let attr_name = input.step(|cursor| match cursor.ident() {
|
let attr_name = input.step(|cursor| match cursor.ident() {
|
||||||
Some((ident, rem)) => Ok((ident, rem)),
|
Some((ident, rem)) => Ok((ident, rem)),
|
||||||
|
@ -19,12 +19,12 @@ path = "src/lib.rs"
|
|||||||
crate-type = ["rlib"]
|
crate-type = ["rlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = { version = "0.4", features = ["std"] }
|
log = { version = "0.4.8", features = ["std"] }
|
||||||
syn = { version = '0.15.0', features = ['full'] }
|
syn = { version = '0.15.44', features = ['full'] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
simple_logger = "1.0" # used in doc test
|
simple_logger = "1.6.0" # used in doc test
|
||||||
lazy_static = "1.3.0" # used in doc test
|
lazy_static = "1.4.0" # used in doc test
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# Turn on the Wasm logger.
|
# Turn on the Wasm logger.
|
||||||
|
@ -29,8 +29,7 @@
|
|||||||
unused_unsafe,
|
unused_unsafe,
|
||||||
unreachable_patterns
|
unreachable_patterns
|
||||||
)]
|
)]
|
||||||
|
#![warn(rust_2018_idioms)]
|
||||||
extern crate core;
|
|
||||||
|
|
||||||
pub mod memory;
|
pub mod memory;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ use std::io;
|
|||||||
pub struct MemError(String);
|
pub struct MemError(String);
|
||||||
|
|
||||||
impl Display for MemError {
|
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)
|
write!(f, "MemError({:?})", self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
pub mod errors;
|
pub mod errors;
|
||||||
|
|
||||||
use self::errors::MemError;
|
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::mem;
|
||||||
use std::num::NonZeroUsize;
|
use std::num::NonZeroUsize;
|
||||||
use std::ptr::{self, NonNull};
|
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>> {
|
pub unsafe fn alloc(size: NonZeroUsize) -> MemResult<NonNull<u8>> {
|
||||||
let layout: Layout = Layout::from_size_align(size.get(), mem::align_of::<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
|
/// 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<()> {
|
pub unsafe fn dealloc(ptr: NonNull<u8>, size: NonZeroUsize) -> MemResult<()> {
|
||||||
let layout = Layout::from_size_align(size.get(), mem::align_of::<u8>())?;
|
let layout = Layout::from_size_align(size.get(), mem::align_of::<u8>())?;
|
||||||
Global.dealloc(ptr, layout);
|
global_dealloc(ptr.as_ptr(), layout);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
unused_unsafe,
|
unused_unsafe,
|
||||||
unreachable_patterns
|
unreachable_patterns
|
||||||
)]
|
)]
|
||||||
|
#![warn(rust_2018_idioms)]
|
||||||
|
|
||||||
extern crate fluence_sdk_macro;
|
extern crate fluence_sdk_macro;
|
||||||
extern crate fluence_sdk_main;
|
extern crate fluence_sdk_main;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user