Skip to content

Commit

Permalink
Refactor target endian
Browse files Browse the repository at this point in the history
  • Loading branch information
p4ken committed May 23, 2024
1 parent 24bfd1a commit 2942054
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/par.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// to use slice::from_raw_parts()
#![cfg(target_endian = "little")]

//! Parameters grid.
use std::{mem, slice};
Expand All @@ -17,6 +14,9 @@ impl Table {
const fn records(&self) -> &[Record] {
let data = self.bytes.as_ptr() as _;
let len = self.bytes.len() / mem::size_of::<Record>();

#[cfg(not(target_endian = "little"))]
compile_error!("target must be little endian");
unsafe { slice::from_raw_parts(data, len) }
}
}
Expand Down Expand Up @@ -46,6 +46,7 @@ mod tests {
fn table_records() {
let records = TKY2JGD.records();
assert_eq!(records.len(), 392323);

let r = records.last().unwrap();
assert_eq!(r.grid_lat, 5463);
assert_eq!(r.grid_lon, 3356);
Expand Down

0 comments on commit 2942054

Please sign in to comment.