Skip to content

Commit

Permalink
Remove full feature (#408)
Browse files Browse the repository at this point in the history
* Provide seperate feature for string implementations

* Revert "Provide seperate feature for string implementations"

This reverts commit 8ead745.

* Derive for all types even without `full` feature

* Adapt PR
  • Loading branch information
athei committed Feb 10, 2023
1 parent c8dc187 commit 400f0fd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 50 deletions.
23 changes: 12 additions & 11 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ default:

#### stage: check

check-rust-stable-no_derive_no_std_full:
stage: check
<<: *docker-env
variables:
RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings"
script:
- time cargo +stable check --verbose --no-default-features --features bit-vec,bytes,generic-array,full


check-rust-stable-no_derive_no_std:
stage: check
<<: *docker-env
Expand All @@ -69,13 +60,13 @@ check-rust-stable-no_std-chain-error:
- time cargo +stable check --verbose --no-default-features --features chain-error


check-rust-stable-no_derive_full:
check-rust-stable-no_derive:
stage: check
<<: *docker-env
variables:
RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings"
script:
- time cargo +stable check --verbose --features bit-vec,bytes,generic-array,full
- time cargo +stable check --verbose --features bit-vec,bytes,generic-array


#### stage: test
Expand Down Expand Up @@ -124,6 +115,16 @@ build-no-std:
- rustup target add thumbv6m-none-eabi
- time cargo build --target thumbv6m-none-eabi --no-default-features

build-no-atomic-ptrs:
stage: test
<<: *docker-env
variables:
RUST_BACKTRACE: 1
script:
# this target doesn't have atomic ptrs. Some parts of alloc are not available there
# we want to make sure that this crate still works on those targets
- cargo +nightly check --target bpfel-unknown-none -Zbuild-std="core,alloc" --no-default-features --features generic-array,derive,max-encoded-len,chain-error

#### stage: build

build-linux-ubuntu-amd64:
Expand Down
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ max-encoded-len = ["parity-scale-codec-derive/max-encoded-len"]
# Should not be used in a constrained environment.
chain-error = []

# WARNING: DO _NOT_ USE THIS FEATURE IF YOU ARE WORKING ON CONSENSUS CODE!*
#
# 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.
# This does not do anthing anymore. Remove with the next major release.
full = []

[workspace]
Expand Down
55 changes: 21 additions & 34 deletions src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,17 @@ use core::num::{

use byte_slice_cast::{AsByteSlice, AsMutByteSlice, ToMutByteSlice};

#[cfg(any(feature = "std", feature = "full"))]
#[cfg(target_has_atomic = "ptr")]
use crate::alloc::sync::Arc;
use crate::alloc::{
string::String,
sync::Arc,
rc::Rc,
};
use crate::alloc::{
vec::Vec,
boxed::Box,
borrow::{Cow, ToOwned},
collections::{
BTreeMap, BTreeSet, VecDeque, LinkedList, BinaryHeap
}
},
rc::Rc,
string::String,
vec::Vec,
};
use crate::compact::Compact;
use crate::encode_like::EncodeLike;
Expand Down Expand Up @@ -212,10 +210,7 @@ pub enum TypeInfo {
I64,
U128,
I128,

#[cfg(feature = "full")]
F32,
#[cfg(feature = "full")]
F64,
}

Expand Down Expand Up @@ -365,24 +360,23 @@ impl<'a, T: ToOwned + Encode + ?Sized> EncodeLike for Cow<'a, T> {}
impl<'a, T: ToOwned + Encode> EncodeLike<T> for Cow<'a, T> {}
impl<'a, T: ToOwned + Encode> EncodeLike<Cow<'a, T>> for T {}

#[cfg(any(feature = "std", feature = "full"))]
mod feature_full_wrapper_type_encode {
use super::*;
impl<T: ?Sized> WrapperTypeEncode for Rc<T> {}
impl<T: ?Sized + Encode> EncodeLike for Rc<T> {}
impl<T: Encode> EncodeLike<T> for Rc<T> {}
impl<T: Encode> EncodeLike<Rc<T>> for T {}

impl WrapperTypeEncode for String {}
impl EncodeLike for String {}
impl EncodeLike<&str> for String {}
impl EncodeLike<String> for &str {}

#[cfg(target_has_atomic = "ptr")]
mod atomic_ptr_targets {
use super::*;
impl<T: ?Sized> WrapperTypeEncode for Arc<T> {}
impl<T: ?Sized + Encode> EncodeLike for Arc<T> {}
impl<T: Encode> EncodeLike<T> for Arc<T> {}
impl<T: Encode> EncodeLike<Arc<T>> for T {}

impl<T: ?Sized> WrapperTypeEncode for Rc<T> {}
impl<T: ?Sized + Encode> EncodeLike for Rc<T> {}
impl<T: Encode> EncodeLike<T> for Rc<T> {}
impl<T: Encode> EncodeLike<Rc<T>> for T {}

impl WrapperTypeEncode for String {}
impl EncodeLike for String {}
impl EncodeLike<&str> for String {}
impl EncodeLike<String> for &str {}
}

#[cfg(feature = "bytes")]
Expand Down Expand Up @@ -498,12 +492,11 @@ pub trait WrapperTypeDecode: Sized {
impl<T> WrapperTypeDecode for Box<T> {
type Wrapped = T;
}
#[cfg(any(feature = "std", feature = "full"))]
impl<T> WrapperTypeDecode for Arc<T> {
impl<T> WrapperTypeDecode for Rc<T> {
type Wrapped = T;
}
#[cfg(any(feature = "std", feature = "full"))]
impl<T> WrapperTypeDecode for Rc<T> {
#[cfg(target_has_atomic = "ptr")]
impl<T> WrapperTypeDecode for Arc<T> {
type Wrapped = T;
}

Expand Down Expand Up @@ -540,10 +533,7 @@ macro_rules! with_type_info {
TypeInfo::U128 => { $macro!(u128 $( $( , $params )* )? ) },
TypeInfo::I128 => { $macro!(i128 $( $( , $params )* )? ) },
TypeInfo::Unknown => { $( $unknown_variant )* },

#[cfg(feature = "full")]
TypeInfo::F32 => { $macro!(f32 $( $( , $params )* )? ) },
#[cfg(feature = "full")]
TypeInfo::F64 => { $macro!(f64 $( $( , $params )* )? ) },
}
};
Expand Down Expand Up @@ -941,7 +931,6 @@ impl<T> Decode for PhantomData<T> {
}
}

#[cfg(any(feature = "std", feature = "full"))]
impl Decode for String {
fn decode<I: Input>(input: &mut I) -> Result<Self, Error> {
Self::from_utf8(Vec::decode(input)?).map_err(|_| "Invalid utf8 sequence".into())
Expand Down Expand Up @@ -1345,7 +1334,6 @@ macro_rules! impl_one_byte {
impl_endians!(u16; U16, u32; U32, u64; U64, u128; U128, i16; I16, i32; I32, i64; I64, i128; I128);
impl_one_byte!(u8; U8, i8; I8);

#[cfg(feature = "full")]
impl_endians!(f32; F32, f64; F64);

impl EncodeLike for bool {}
Expand Down Expand Up @@ -1888,7 +1876,6 @@ mod tests {

test_array_encode_and_decode!(u8, i8, u16, i16, u32, i32, u64, i64, u128, i128);

#[cfg(feature = "full")]
test_array_encode_and_decode!(f32, f64);

fn test_encoded_size(val: impl Encode) {
Expand Down

0 comments on commit 400f0fd

Please sign in to comment.