Skip to content

Commit e8bd2e0

Browse files
committed
Serialize const arrays with serde_with
1 parent a16b932 commit e8bd2e0

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

rand_distr/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ serde1 = ["serde", "rand/serde1"]
2727
rand = { path = "..", version = "0.9.0", default-features = false }
2828
num-traits = { version = "0.2", default-features = false, features = ["libm"] }
2929
serde = { version = "1.0.103", features = ["derive"], optional = true }
30+
serde_with = { version = "1.14.0", optional = true }
3031

3132
[dev-dependencies]
3233
rand_pcg = { version = "0.4.0", path = "../rand_pcg" }

rand_distr/src/dirichlet.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use num_traits::Float;
1313
use crate::{Distribution, Exp1, Gamma, Open01, StandardNormal};
1414
use rand::Rng;
1515
use core::fmt;
16+
#[cfg(feature = "serde_with")]
17+
use serde_with::serde_as;
1618

1719
/// The Dirichlet distribution `Dirichlet(alpha)`.
1820
///
@@ -31,8 +33,8 @@ use core::fmt;
3133
/// println!("{:?} is from a Dirichlet([1.0, 2.0, 3.0]) distribution", samples);
3234
/// ```
3335
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
36+
#[cfg_attr(feature = "serde_with", serde_as)]
3437
#[derive(Clone, Debug, PartialEq)]
35-
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
3638
pub struct Dirichlet<F, const N: usize>
3739
where
3840
F: Float,
@@ -41,6 +43,7 @@ where
4143
Open01: Distribution<F>,
4244
{
4345
/// Concentration parameters (alpha)
46+
#[cfg_attr(feature = "serde_with", serde_as(as = "[_; N]"))]
4447
alpha: [F; N],
4548
}
4649

0 commit comments

Comments
 (0)