Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Schema for nalgebra matrix type #175

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
9 changes: 9 additions & 0 deletions source/postcard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ optional = true
version = "1.0.12"
optional = true

[dependencies.nalgebra-0_33]
package = "nalgebra"
version = "0.33.0"
jamesmunns marked this conversation as resolved.
Show resolved Hide resolved
optional = true
default-features = false

[features]
default = ["heapless-cas"]

Expand All @@ -77,6 +83,9 @@ embedded-io = ["dep:embedded-io-04"]
embedded-io-04 = ["dep:embedded-io-04"]
embedded-io-06 = ["dep:embedded-io-06"]

# Specific versions of `nalgebra` can be selected through the features below
nalgebra-0_33 = ["dep:nalgebra-0_33"]

use-std = ["serde/std", "alloc"]
heapless-cas = ["heapless", "heapless/cas"]
alloc = ["serde/alloc", "embedded-io-04?/alloc", "embedded-io-06?/alloc"]
Expand Down
18 changes: 18 additions & 0 deletions source/postcard/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,24 @@ impl Schema for std::string::String {
};
}

#[cfg(feature = "nalgebra-0_33")]
#[cfg_attr(docsrs, doc(cfg(feature = "nalgebra-0_33")))]
impl<T, const R: usize, const C: usize> Schema
for nalgebra_0_33::Matrix<
T,
nalgebra_0_33::Const<R>,
nalgebra_0_33::Const<C>,
nalgebra_0_33::ArrayStorage<T, R, C>,
>
where
T: Schema + nalgebra_0_33::Scalar,
{
const SCHEMA: &'static NamedType = &NamedType {
name: "nalgebra::Matrix<T, R, C, ArrayStorage<T, R, C>>",
ty: &SdmTy::Seq(T::SCHEMA),
};
}

#[cfg(all(not(feature = "use-std"), feature = "alloc"))]
extern crate alloc;

Expand Down