Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bit-vec feature
  • Loading branch information
ascjones committed Jun 18, 2021
commit 61df8b9e9f51430bdab51479ceea9ea4ff348c23
1 change: 1 addition & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:

- name: check-features
run: |
cargo check --no-default-features --features bit-vec
cargo check --no-default-features --features serde
cargo check --no-default-features --features serde,decode

Expand Down
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ categories = ["no-std", "encoding"]
include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]

[dependencies]
bitvec = { version = "0.20.1", default-features = false }
bitvec = { version = "0.20.1", default-features = false, features = ["alloc"], optional = true }
cfg-if = "1.0"
scale-info-derive = { version = "0.4.0", path = "derive", default-features = false, optional = true }
serde = { version = "1", default-features = false, optional = true, features = ["derive", "alloc"] }
Expand All @@ -24,6 +24,7 @@ scale = { package = "parity-scale-codec", version = "2.1", default-features = fa
[features]
default = ["std"]
std = [
"bitvec/std",
"scale/std",
]
derive = [
Expand All @@ -33,6 +34,10 @@ derive = [
decode = [
"scale/full"
]
# enables type information for bitvec types, matching the name of the parity-scale-codec feature
bit-vec = [
"bitvec"
]

[workspace]
members = [
Expand Down
6 changes: 4 additions & 2 deletions src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use crate::{
Path,
Type,
TypeDefArray,
TypeDefBitVec,
TypeDefCompact,
TypeDefPhantom,
TypeDefPrimitive,
Expand Down Expand Up @@ -288,6 +287,7 @@ where
}
}

#[cfg(feature = "bit-vec")]
impl<O, T> TypeInfo for bitvec::vec::BitVec<O, T>
where
O: bitvec::order::BitOrder + TypeInfo + 'static,
Expand All @@ -296,10 +296,11 @@ where
type Identity = Self;

fn type_info() -> Type {
TypeDefBitVec::new::<O, T>().into()
crate::TypeDefBitVec::new::<O, T>().into()
}
}

#[cfg(feature = "bit-vec")]
impl TypeInfo for bitvec::order::Lsb0 {
type Identity = Self;

Expand All @@ -310,6 +311,7 @@ impl TypeInfo for bitvec::order::Lsb0 {
}
}

#[cfg(feature = "bit-vec")]
impl TypeInfo for bitvec::order::Msb0 {
type Identity = Self;

Expand Down
18 changes: 15 additions & 3 deletions src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,15 @@ impl_from_type_def_for_type!(
TypeDefTuple,
TypeDefCompact,
TypeDefPhantom,
TypeDefBitVec,
);

#[cfg(feature = "bit-vec")]
impl From<crate::TypeDefBitVec> for Type {
fn from(item: crate::TypeDefBitVec) -> Self {
Self::new(Path::voldemort(), Vec::new(), item, Vec::new())
}
}

impl Type {
/// Create a [`TypeBuilder`](`crate::build::TypeBuilder`) the public API for constructing a [`Type`]
pub fn builder() -> TypeBuilder {
Expand Down Expand Up @@ -198,6 +204,7 @@ pub enum TypeDef<T: Form = MetaForm> {
Compact(TypeDefCompact<T>),
/// A PhantomData type.
Phantom(TypeDefPhantom<T>),
#[cfg(feature = "bit-vec")]
/// A BitVec type.
BitVec(TypeDefBitVec<T>),
}
Expand All @@ -215,6 +222,7 @@ impl IntoPortable for TypeDef {
TypeDef::Primitive(primitive) => primitive.into(),
TypeDef::Compact(compact) => compact.into_portable(registry).into(),
TypeDef::Phantom(phantom) => phantom.into_portable(registry).into(),
#[cfg(feature = "bit-vec")]
TypeDef::BitVec(bitvec) => bitvec.into_portable(registry).into(),
}
}
Expand Down Expand Up @@ -491,6 +499,7 @@ where
}

/// Type describing a [`bitvec::vec::BitVec`].
#[cfg(feature = "bit-vec")]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature = "std", feature = "decode"), derive(scale::Decode))]
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Debug)]
Expand All @@ -501,8 +510,9 @@ pub struct TypeDefBitVec<T: Form = MetaForm> {
bit_order_type: T::Type,
}

impl IntoPortable for TypeDefBitVec {
type Output = TypeDefBitVec<PortableForm>;
#[cfg(feature = "bit-vec")]
impl IntoPortable for crate::TypeDefBitVec {
type Output = crate::TypeDefBitVec<PortableForm>;

fn into_portable(self, registry: &mut Registry) -> Self::Output {
TypeDefBitVec {
Expand All @@ -512,6 +522,7 @@ impl IntoPortable for TypeDefBitVec {
}
}

#[cfg(feature = "bit-vec")]
impl TypeDefBitVec {
/// Creates a new phantom type definition.
pub fn new<O, T>() -> Self
Expand All @@ -526,6 +537,7 @@ impl TypeDefBitVec {
}
}

#[cfg(feature = "bit-vec")]
impl<T> TypeDefBitVec<T>
where
T: Form,
Expand Down