Skip to content

Commit

Permalink
"glam" and "arrayvec" features compatible with no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
poshcoe committed Apr 19, 2024
1 parent a2a22c7 commit b11e16a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Test (all-features)
run: cargo test --all-features
- name: Test (no_std)
run: cargo test --no-default-features --features derive,serde
run: cargo test --no-default-features --features derive,serde,glam,arrayvec
- name: Install i686 and GCC multilib
run: rustup target add i686-unknown-linux-gnu && sudo apt update && sudo apt install -y gcc-multilib
- name: Test (32-bit all-features)
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exclude = ["fuzz/"]
arrayvec = { version = "0.7", default-features = false, optional = true }
bitcode_derive = { version = "0.6.0", path = "./bitcode_derive", optional = true }
bytemuck = { version = "1.14", features = [ "min_const_generics", "must_cast" ] }
glam = { version = ">=0.21", default-features = false, features = [ "std" ], optional = true }
glam = { version = ">=0.21", default-features = false, optional = true }
serde = { version = "1.0", default-features = false, features = [ "alloc" ], optional = true }

[dev-dependencies]
Expand All @@ -37,7 +37,7 @@ zstd = "0.13.0"

[features]
derive = [ "bitcode_derive" ]
std = [ "serde?/std" ]
std = [ "serde?/std", "glam?/std", "arrayvec?/std" ]
default = [ "derive", "std" ]

[package.metadata.docs.rs]
Expand Down
5 changes: 3 additions & 2 deletions src/ext/arrayvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::derive::{Decode, Encode};
use crate::error::err;
use crate::str::{StrDecoder, StrEncoder};
use arrayvec::{ArrayString, ArrayVec};
use std::mem::MaybeUninit;
use core::mem::MaybeUninit;

// TODO optimize ArrayVec impls and make ArrayString use them.
impl<const N: usize> Encoder<ArrayString<N>> for StrEncoder {
Expand Down Expand Up @@ -111,7 +111,7 @@ fn as_slice_assert_len<T, const N: usize>(t: &ArrayVec<T, N>) -> &[T] {
let s = t.as_slice();
// Safety: ArrayVec<N> has length <= N. TODO replace with LengthDecoder<N>.
if s.len() > N {
unsafe { std::hint::unreachable_unchecked() };
unsafe { core::hint::unreachable_unchecked() };
}
s
}
Expand Down Expand Up @@ -173,6 +173,7 @@ impl<'a, T: Decode<'a>, const N: usize> Decode<'a> for ArrayVec<T, N> {
#[cfg(test)]
mod tests {
use crate::{decode, encode};
use alloc::vec::Vec;
use arrayvec::{ArrayString, ArrayVec};

// Smaller set of tests for ArrayString than ArrayVec they share VecEncoder/LengthDecoder.
Expand Down
2 changes: 2 additions & 0 deletions src/ext/glam.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::impl_struct;
use alloc::vec::Vec;
use glam::*;

trait Affine3AExt {
Expand Down Expand Up @@ -43,6 +44,7 @@ impl_glam!(bool, BVec2, BVec3, BVec4);

#[cfg(test)]
mod tests {
use alloc::vec::Vec;
use glam::Vec2;
fn bench_data() -> Vec<Vec2> {
crate::random_data(1000)
Expand Down
2 changes: 1 addition & 1 deletion src/ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ macro_rules! impl_struct {
)+
}

fn reserve(&mut self, additional: std::num::NonZeroUsize) {
fn reserve(&mut self, additional: core::num::NonZeroUsize) {
$(
self.$f.reserve(additional);
)+
Expand Down
2 changes: 1 addition & 1 deletion src/serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn get_mut_or_resize<T: Default>(vec: &mut Vec<T>, index: usize) -> &mut T {
unsafe { vec.get_unchecked_mut(index) }
}

//#[cfg(not(feature = "std"))]
#[cfg(not(feature = "std"))]
impl serde::ser::StdError for Error {}

impl serde::ser::Error for Error {
Expand Down

0 comments on commit b11e16a

Please sign in to comment.