Skip to content

Commit 096f1e8

Browse files
authored
Fix Option wrong sizing (#60)
1 parent 5f7bfd1 commit 096f1e8

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ members = ["codegen", "tools/create-data-file", "tools/dump-data-file"]
33

44
[package]
55
name = "data_bucket"
6-
version = "0.3.9"
6+
version = "0.3.10"
77
edition = "2021"
88
authors = ["Handy-caT"]
99
license = "MIT"

src/util/sized.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ impl<T: SizeMeasurable> SizeMeasurable for Option<T>
176176
where
177177
T: SizeMeasurable,
178178
{
179+
fn align() -> Option<usize> {
180+
T::align()
181+
}
182+
179183
fn aligned_size(&self) -> usize {
180184
size_of::<Option<T>>()
181185
}
@@ -295,11 +299,24 @@ mod test {
295299
to_bytes::<rkyv::rancor::Error>(&t).unwrap().len()
296300
);
297301
let t = (u8::MAX, Link::default());
302+
assert_eq!(
303+
t.aligned_size(),
304+
to_bytes::<rkyv::rancor::Error>(&t).unwrap().len()
305+
);
306+
let t = (Some(0.0f64), Link::default());
298307
assert_eq!(
299308
t.aligned_size(),
300309
to_bytes::<rkyv::rancor::Error>(&t).unwrap().len()
301310
)
302311
}
312+
#[test]
313+
fn test_option() {
314+
let t = Some(0.0f64);
315+
assert_eq!(
316+
t.aligned_size(),
317+
to_bytes::<rkyv::rancor::Error>(&t).unwrap().len()
318+
);
319+
}
303320

304321
#[test]
305322
fn test_string() {

0 commit comments

Comments
 (0)