Unverified Commit 78c65a28 authored by thiolliere's avatar thiolliere Committed by GitHub
Browse files

no std works on stable + CI (#129)

* no std works on stable + CI

* bump version to 0.1
parent 422213e5
Pipeline #43655 passed with stages
in 13 minutes and 35 seconds
......@@ -48,6 +48,48 @@ test:rust:stable:no_derive:
tags:
- rust
check:rust:stable:no_derive_no_std_full:
stage: test
script:
- time cargo check --verbose --no-default-features --features bit-vec,full
only:
- triggers
- tags
- master
- schedules
- web
- /^[0-9]+$/
tags:
- rust
check:rust:stable:no_derive_no_std:
stage: test
script:
- time cargo check --verbose --no-default-features --features bit-vec
only:
- triggers
- tags
- master
- schedules
- web
- /^[0-9]+$/
tags:
- rust
check:rust:stable:no_derive_full:
stage: test
script:
- time cargo check --verbose --features bit-vec,full
only:
- triggers
- tags
- master
- schedules
- web
- /^[0-9]+$/
tags:
- rust
bench:rust:nightly:
stage: test
script:
......
[package]
name = "parity-scale-codec"
description = "SCALE - Simple Concatenating Aggregated Little Endians"
version = "1.0.0"
version = "1.0.1"
authors = ["Parity Technologies <admin@parity.io>"]
license = "Apache-2.0"
repository = "https://github.com/paritytech/parity-scale-codec"
......@@ -38,7 +38,7 @@ bit-vec = ["bitvec", "byte-slice-cast"]
#
# Provides implementations for more data structures than just Vec and Box.
# Concretely it will provide parity-scale-codec implementations for many types
# that can be found in std and/or alloc (nightly).
# that can be found in std and/or alloc.
full = []
[workspace]
......
......@@ -17,13 +17,14 @@
use crate::alloc::vec::Vec;
use crate::alloc::boxed::Box;
use crate::alloc::collections::{BTreeMap, BTreeSet, VecDeque, LinkedList, BinaryHeap};
use crate::compact::{Compact, CompactLen};
#[cfg(any(feature = "std", feature = "full"))]
use crate::alloc::{
string::String,
borrow::Cow,
borrow::{Cow, ToOwned},
sync::Arc,
rc::Rc,
};
use core::{mem, slice, ops::Deref};
......@@ -44,6 +45,7 @@ pub struct Error(&'static str);
#[cfg(not(feature = "std"))]
#[derive(PartialEq)]
/// Undescriptive error type when compiled for no std
pub struct Error;
impl Error {
......@@ -145,7 +147,6 @@ pub struct IoReader<R: std::io::Read> {
reader: R,
}
// TODO TODO: either test it or remove it
#[cfg(feature = "std")]
impl<R: std::io::Read> Input for IoReader<R> {
fn require_min_len(&mut self, len: usize) -> Result<(), Error> {
......@@ -305,9 +306,9 @@ impl<'a, T: ?Sized> WrapperTypeEncode for &'a mut T {}
#[cfg(any(feature = "std", feature = "full"))]
impl<'a, T: ToOwned + ?Sized> WrapperTypeEncode for Cow<'a, T> {}
#[cfg(any(feature = "std", feature = "full"))]
impl<T: ?Sized> WrapperTypeEncode for std::sync::Arc<T> {}
impl<T: ?Sized> WrapperTypeEncode for Arc<T> {}
#[cfg(any(feature = "std", feature = "full"))]
impl<T: ?Sized> WrapperTypeEncode for std::rc::Rc<T> {}
impl<T: ?Sized> WrapperTypeEncode for Rc<T> {}
#[cfg(any(feature = "std", feature = "full"))]
impl WrapperTypeEncode for String {}
......@@ -343,11 +344,11 @@ impl<T> WrapperTypeDecode for Box<T> {
type Wrapped = T;
}
#[cfg(any(feature = "std", feature = "full"))]
impl<T> WrapperTypeDecode for std::sync::Arc<T> {
impl<T> WrapperTypeDecode for Arc<T> {
type Wrapped = T;
}
#[cfg(any(feature = "std", feature = "full"))]
impl<T> WrapperTypeDecode for std::rc::Rc<T> {
impl<T> WrapperTypeDecode for Rc<T> {
type Wrapped = T;
}
......@@ -601,7 +602,7 @@ impl<T: Encode> Encode for [T] {
Compact(len as u32).encode_to(dest);
if let IsU8::Yes= <T as Encode>::IS_U8 {
let self_transmute = unsafe {
std::mem::transmute::<&[T], &[u8]>(self)
core::mem::transmute::<&[T], &[u8]>(self)
};
dest.write(self_transmute)
} else {
......@@ -625,7 +626,7 @@ impl<T: Decode> Decode for Vec<T> {
let mut r = vec![0; len];
input.read(&mut r[..len])?;
let r = unsafe { std::mem::transmute::<Vec<u8>, Vec<T>>(r) };
let r = unsafe { core::mem::transmute::<Vec<u8>, Vec<T>>(r) };
Ok(r)
} else {
input.require_min_len(len * T::min_encoded_len())?;
......@@ -735,7 +736,7 @@ impl<T: Encode + Ord> Encode for VecDeque<T> {
if let IsU8::Yes = <T as Encode>::IS_U8 {
let slices = self.as_slices();
let slices_transmute = unsafe {
std::mem::transmute::<(&[T], &[T]), (&[u8], &[u8])>(slices)
core::mem::transmute::<(&[T], &[T]), (&[u8], &[u8])>(slices)
};
dest.write(slices_transmute.0);
dest.write(slices_transmute.1);
......@@ -879,7 +880,7 @@ macro_rules! tuple_impl {
#[allow(non_snake_case)]
mod inner_tuple_impl {
use super::{Error, Input, Output, Decode, Encode};
use super::{Error, Input, Output, Decode, Encode, Vec};
tuple_impl!(A, B, C, D, E, F, G, H, I, J, K,);
}
......
......@@ -14,6 +14,7 @@
//! [Compact encoding](https://substrate.dev/docs/en/overview/low-level-data-format#compact-general-integers)
use crate::alloc::vec::Vec;
use crate::codec::{Input, Output, Error, Encode, Decode, EncodeAsRef};
use arrayvec::ArrayVec;
......
......@@ -206,7 +206,6 @@
#![warn(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]
#[cfg(not(feature = "std"))]
#[macro_use]
......@@ -233,13 +232,8 @@ pub mod alloc {
pub use std::string;
pub use std::borrow;
pub use std::collections;
#[cfg(feature = "full")]
mod full {
pub use std::borrow;
}
#[cfg(feature = "full")]
pub use self::full::*;
pub use std::sync;
pub use std::rc;
}
mod codec;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment