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

Add workaround for the deserialization of a matrix containing an enum. #813

Merged
merged 1 commit into from
Dec 18, 2020
Merged
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
2 changes: 1 addition & 1 deletion src/base/array_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ where
where
V: SeqAccess<'a>,
{
let mut out: Self::Value = unsafe { mem::uninitialized() };
let mut out: Self::Value = unsafe { mem::MaybeUninit::uninit().assume_init() };
let mut curr = 0;

while let Some(value) = visitor.next_element()? {
Expand Down
5 changes: 2 additions & 3 deletions src/base/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,8 @@ macro_rules! impl_from_into_mint_1D(
#[inline]
fn into(self) -> mint::$VT<N> {
unsafe {
let mut res: mint::$VT<N> = mem::uninitialized();
let mut res: mint::$VT<N> = mem::MaybeUninit::uninit().assume_init();
ptr::copy_nonoverlapping(self.data.ptr(), &mut res.x, $SZ);

res
}
}
Expand Down Expand Up @@ -324,7 +323,7 @@ macro_rules! impl_from_into_mint_2D(
#[inline]
fn into(self) -> mint::$MV<N> {
unsafe {
let mut res: mint::$MV<N> = mem::uninitialized();
let mut res: mint::$MV<N> = mem::MaybeUninit::uninit().assume_init();
let mut ptr = self.data.ptr();
$(
ptr::copy_nonoverlapping(ptr, &mut res.$component.x, $SZRows);
Expand Down
16 changes: 15 additions & 1 deletion tests/core/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
use na::{
DMatrix, Isometry2, Isometry3, IsometryMatrix2, IsometryMatrix3, Matrix3x4, Point2, Point3,
Quaternion, Rotation2, Rotation3, Similarity2, Similarity3, SimilarityMatrix2,
SimilarityMatrix3, Translation2, Translation3, Unit,
SimilarityMatrix3, Translation2, Translation3, Unit, Vector2,
};
use rand;
use serde::{Deserialize, Serialize};
use serde_json;

macro_rules! test_serde(
Expand Down Expand Up @@ -54,3 +55,16 @@ fn serde_flat() {
let serialized = serde_json::to_string(&v).unwrap();
assert_eq!(serialized, "[0.0,0.0,1.0,0.0]");
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Copy, Clone)]
enum Stuff {
A(f64),
B(f64),
}

#[test]
fn deserialize_enum() {
let json = r#"[{"letter":"A", "value":123.4}, {"letter":"B", "value":567.8}]"#;
let parsed: Result<Vector2<Stuff>, _> = serde_json::from_str(json);
println!("parsed: {:?}", parsed);
}