Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
matrix:
os: [ubuntu-latest]
rust:
- 1.55.0 # approximate MSRV is Stable -30
- 1.60.0 # approximate MSRV is Stable -30
- stable
- beta
- nightly
Expand All @@ -28,11 +28,11 @@ jobs:
toolchain: ${{ matrix.rust }}
# On MSRV some dev-dependencies don't build so we can't run tests.
- name: Check MSRV
if: matrix.rust == '1.55.0'
if: matrix.rust == '1.60.0'
run: |
cargo check --features=alloc,std,grab_spare_slice
- name: Test non nightly
if: matrix.rust != '1.55.0' && matrix.rust != 'nightly'
if: matrix.rust != '1.60.0' && matrix.rust != 'nightly'
run: |
cargo test --features=alloc,std,grab_spare_slice,latest_stable_rust
- name: Test on Nightly with All Features
Expand Down
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ arbitrary = { version = "1", optional = true }
borsh = { version = "1.2.0", optional = true, default-features = false }
# Implements the trait `Array` for `GenericArray` struct.
generic-array = { version = "1.1.1", optional = true, default-features = false }
# Provides `JsonSchema` implementations
schemars = { version = "1.0", optional = true, default-features = false }


[features]
Expand Down Expand Up @@ -75,12 +77,14 @@ experimental_write_impl = []
# and thus a nightly compiler, but is only used in benchmarks.
real_blackbox = ["criterion/real_blackbox"]

schemars = ["dep:schemars", "alloc"]

[package.metadata.docs.rs]
features = ["alloc", "std", "grab_spare_slice", "latest_stable_rust", "serde", "borsh"]
features = ["alloc", "std", "grab_spare_slice", "latest_stable_rust", "serde", "borsh", "schemars"]
rustdoc-args = ["--cfg","docs_rs"]

[package.metadata.playground]
features = ["alloc", "std", "grab_spare_slice", "latest_stable_rust", "serde", "borsh"]
features = ["alloc", "std", "grab_spare_slice", "latest_stable_rust", "serde", "borsh", "schemars"]

[profile.bench]
debug = 2
Expand Down
27 changes: 27 additions & 0 deletions src/arrayvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,33 @@ where
}
}

#[cfg(feature = "schemars")]
#[cfg_attr(docs_rs, doc(cfg(feature = "schemars")))]
impl<A> schemars::JsonSchema for ArrayVec<A>
where
A: Array,
<A as Array>::Item: schemars::JsonSchema,
{
fn schema_name() -> alloc::borrow::Cow<'static, str> {
alloc::format!(
"Array_up_to_size_{}_of_{}",
A::CAPACITY,
<A as Array>::Item::schema_name()
)
.into()
}

fn json_schema(
generator: &mut schemars::SchemaGenerator,
) -> schemars::Schema {
schemars::json_schema!({
"type": "array",
"items": generator.subschema_for::<<A as Array>::Item>(),
"maxItems": A::CAPACITY
})
}
}

impl<A: Array> ArrayVec<A> {
/// Move all values from `other` into this vec.
///
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
//! * `borsh` provides a `BorshSerialize` and `BorshDeserialize` implementation
//! for [`TinyVec`] and [`ArrayVec`] types, provided the inner item also has
//! an implementation.
//! * `schemars` provides a `JsonSchema` implementation for [`TinyVec`] and
//! [`ArrayVec`] types, provided the inner item also has an implementation.
//!
//! ## API
//! The general goal of the crate is that, as much as possible, the vecs here
Expand Down
27 changes: 27 additions & 0 deletions src/tinyvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,33 @@ where
}
}

#[cfg(feature = "schemars")]
#[cfg_attr(docs_rs, doc(cfg(feature = "schemars")))]
impl<A> schemars::JsonSchema for TinyVec<A>
where
A: Array,
<A as Array>::Item: schemars::JsonSchema,
{
fn schema_name() -> alloc::borrow::Cow<'static, str> {
alloc::format!(
"Array_up_to_size_{}_of_{}",
A::CAPACITY,
<A as Array>::Item::schema_name()
)
.into()
}

fn json_schema(
generator: &mut schemars::SchemaGenerator,
) -> schemars::Schema {
schemars::json_schema!({
"type": "array",
"items": generator.subschema_for::<<A as Array>::Item>(),
"maxItems": A::CAPACITY
})
}
}

impl<A: Array> TinyVec<A> {
/// Returns whether elements are on heap
#[inline(always)]
Expand Down
Loading