diff --git a/Cargo.toml b/Cargo.toml index e5e16e32..2d6f9c8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["anise", "anise-cli", "anise-gui", "anise-py"] [workspace.package] -version = "0.4.5" +version = "0.5.0" edition = "2021" authors = ["Christopher Rabotin "] description = "ANISE provides a toolkit and files for Attitude, Navigation, Instrument, Spacecraft, and Ephemeris data. It's a modern replacement of NAIF SPICE file." @@ -38,7 +38,7 @@ nalgebra = { version = "0.33", default-features = true, features = [ "serde-serialize", ] } approx = "0.5.1" -zerocopy = { version = "0.7.26", features = ["derive"] } +zerocopy = { version = "0.8.0", features = ["derive"] } bytes = "1.6.0" snafu = { version = "0.8.0", features = ["backtrace"] } lexical-core = "1.0.1" @@ -50,7 +50,7 @@ serde = "1" serde_derive = "1" serde_dhall = "0.12" -anise = { version = "0.4.5", path = "anise", default-features = false } +anise = { version = "0.5.0", path = "anise", default-features = false } [profile.bench] debug = true diff --git a/anise-cli/src/main.rs b/anise-cli/src/main.rs index f94dd825..86a6cda8 100644 --- a/anise-cli/src/main.rs +++ b/anise-cli/src/main.rs @@ -112,7 +112,7 @@ fn main() -> Result<(), CliErrors> { } } else { // Load the header only - let file_record = FileRecord::read_from(&bytes[..FileRecord::SIZE]).unwrap(); + let file_record = FileRecord::read_from_bytes(&bytes[..FileRecord::SIZE]).unwrap(); match file_record.identification().context(CliFileRecordSnafu)? { "PCK" => { info!("Loading {path_str:?} as DAF/PCK"); @@ -194,7 +194,7 @@ fn main() -> Result<(), CliErrors> { fn read_and_record(path_str: PathBuf) -> Result<(bytes::Bytes, FileRecord), CliErrors> { let bytes = file2heap!(path_str).context(AniseSnafu)?; // Load the header only - let file_record = FileRecord::read_from(&bytes[..FileRecord::SIZE]).unwrap(); + let file_record = FileRecord::read_from_bytes(&bytes[..FileRecord::SIZE]).unwrap(); Ok((bytes, file_record)) } diff --git a/anise/src/almanac/mod.rs b/anise/src/almanac/mod.rs index 63282cd3..9814bf9c 100644 --- a/anise/src/almanac/mod.rs +++ b/anise/src/almanac/mod.rs @@ -121,7 +121,7 @@ impl Almanac { // Load the header only if let Some(file_record_bytes) = bytes.get(..FileRecord::SIZE) { - let file_record = FileRecord::read_from(file_record_bytes).unwrap(); + let file_record = FileRecord::read_from_bytes(file_record_bytes).unwrap(); if let Ok(fileid) = file_record.identification() { return match fileid { "PCK" => { diff --git a/anise/src/naif/daf/daf.rs b/anise/src/naif/daf/daf.rs index 4ddf01b8..7049ba6a 100644 --- a/anise/src/naif/daf/daf.rs +++ b/anise/src/naif/daf/daf.rs @@ -27,7 +27,7 @@ use hifitime::Epoch; use log::{debug, error, trace}; use snafu::ResultExt; -use zerocopy::AsBytes; +use zerocopy::IntoBytes; use zerocopy::{FromBytes, Ref}; macro_rules! io_imports { @@ -76,7 +76,7 @@ impl GenericDAF { } pub fn file_record(&self) -> Result { - let file_record = FileRecord::read_from( + let file_record = FileRecord::read_from_bytes( self.bytes .get(..FileRecord::SIZE) .ok_or_else(|| DecodingError::InaccessibleBytes { @@ -108,7 +108,7 @@ impl GenericDAF { size: self.bytes.len(), }) .context(DecodingNameSnafu { kind: R::NAME })?; - Ok(NameRecord::read_from(rcrd_bytes).unwrap()) + Ok(NameRecord::read_from_bytes(rcrd_bytes).unwrap()) } pub fn daf_summary(&self) -> Result { @@ -123,8 +123,8 @@ impl GenericDAF { }) .context(DecodingSummarySnafu { kind: R::NAME })?; - SummaryRecord::read_from(&rcrd_bytes[..SummaryRecord::SIZE]) - .ok_or(DecodingError::Casting) + SummaryRecord::read_from_bytes(&rcrd_bytes[..SummaryRecord::SIZE]) + .or(Err(DecodingError::Casting)) .context(DecodingSummarySnafu { kind: R::NAME }) } @@ -157,13 +157,15 @@ impl GenericDAF { }; // The summaries are defined in the same record as the DAF summary - Ok(match Ref::new_slice(&rcrd_bytes[SummaryRecord::SIZE..]) { - Some(data) => data.into_slice(), - None => &{ - R::default(); - [] as [R; 0] + Ok( + match Ref::<_, [R]>::from_bytes(&rcrd_bytes[SummaryRecord::SIZE..]) { + Ok(r) => Ref::into_ref(r), + Err(_) => &{ + R::default(); + [] as [R; 0] + }, }, - }) + ) } /// Returns the summary given the name of the summary record @@ -271,27 +273,28 @@ impl GenericDAF { let start = (this_summary.start_index() - 1) * DBL_SIZE; let end = this_summary.end_index() * DBL_SIZE; - let data: &[f64] = Ref::new_slice( - match self - .bytes - .get(start..end) - .ok_or_else(|| DecodingError::InaccessibleBytes { - start, - end, - size: self.bytes.len(), - }) { - Ok(it) => it, - Err(source) => { - return Err(DAFError::DecodingData { - kind: R::NAME, - idx, - source, - }) - } - }, - ) - .unwrap() - .into_slice(); + let data: &[f64] = Ref::into_ref( + Ref::<&[u8], [f64]>::from_bytes( + match self + .bytes + .get(start..end) + .ok_or_else(|| DecodingError::InaccessibleBytes { + start, + end, + size: self.bytes.len(), + }) { + Ok(it) => it, + Err(source) => { + return Err(DAFError::DecodingData { + kind: R::NAME, + idx, + source, + }) + } + }, + ) + .unwrap(), + ); // Convert it S::from_f64_slice(data).context(DecodingDataSnafu { kind: R::NAME, idx }) diff --git a/anise/src/naif/daf/datatypes/posvel.rs b/anise/src/naif/daf/datatypes/posvel.rs index 93919368..04e44c49 100644 --- a/anise/src/naif/daf/datatypes/posvel.rs +++ b/anise/src/naif/daf/datatypes/posvel.rs @@ -9,14 +9,14 @@ */ use core::fmt; -use zerocopy::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{ math::Vector3, naif::daf::{NAIFDataRecord, NAIFRecord}, }; -#[derive(Copy, Clone, Default, AsBytes, FromBytes, FromZeroes, Debug)] +#[derive(Copy, Clone, Default, IntoBytes, FromBytes, KnownLayout, Immutable, Debug)] #[repr(C)] pub struct PositionVelocityRecord { pub x_km: f64, diff --git a/anise/src/naif/daf/file_record.rs b/anise/src/naif/daf/file_record.rs index 42a786c6..2437ec38 100644 --- a/anise/src/naif/daf/file_record.rs +++ b/anise/src/naif/daf/file_record.rs @@ -11,7 +11,7 @@ use std::str::Utf8Error; use snafu::prelude::*; -use zerocopy::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::naif::Endian; use log::error; @@ -42,7 +42,7 @@ pub enum FileRecordError { EmptyRecord, } -#[derive(Debug, Clone, FromBytes, FromZeroes, AsBytes, PartialEq)] +#[derive(Debug, Clone, FromBytes, KnownLayout, Immutable, IntoBytes, PartialEq)] #[repr(C)] pub struct FileRecord { pub id_str: [u8; 8], diff --git a/anise/src/naif/daf/mod.rs b/anise/src/naif/daf/mod.rs index 8108e6dd..22167f15 100644 --- a/anise/src/naif/daf/mod.rs +++ b/anise/src/naif/daf/mod.rs @@ -15,7 +15,7 @@ use crate::{ use core::fmt::Display; use hifitime::Epoch; use snafu::prelude::*; -use zerocopy::{AsBytes, FromBytes}; +use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; pub(crate) const RCRD_LEN: usize = 1024; #[allow(clippy::module_inception)] @@ -39,11 +39,13 @@ pub use summary_record::SummaryRecord; use self::file_record::FileRecordError; -pub trait NAIFRecord: AsBytes + FromBytes + Sized + Default + Debug { +pub trait NAIFRecord: + IntoBytes + FromBytes + Sized + Default + Debug + Immutable + KnownLayout +{ const SIZE: usize = core::mem::size_of::(); } -pub trait NAIFSummaryRecord: NAIFRecord + Copy { +pub trait NAIFSummaryRecord: NAIFRecord + Copy + Immutable + KnownLayout { type Error: 'static + std::error::Error; fn start_index(&self) -> usize; diff --git a/anise/src/naif/daf/mut_daf.rs b/anise/src/naif/daf/mut_daf.rs index b3b90241..1413aa59 100644 --- a/anise/src/naif/daf/mut_daf.rs +++ b/anise/src/naif/daf/mut_daf.rs @@ -23,7 +23,7 @@ use crate::{ use bytes::BytesMut; use hifitime::Epoch; use snafu::ResultExt; -use zerocopy::AsBytes; +use zerocopy::IntoBytes; impl MutDAF { /// Parse the provided bytes as a SPICE Double Array File diff --git a/anise/src/naif/daf/name_record.rs b/anise/src/naif/daf/name_record.rs index 16b785c4..c123e5cf 100644 --- a/anise/src/naif/daf/name_record.rs +++ b/anise/src/naif/daf/name_record.rs @@ -8,14 +8,14 @@ * Documentation: https://nyxspace.com/ */ -use zerocopy::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::DBL_SIZE; use log::warn; use super::{DAFError, NAIFRecord, NAIFSummaryRecord, RCRD_LEN}; -#[derive(AsBytes, Clone, Debug, FromZeroes, FromBytes)] +#[derive(IntoBytes, FromBytes, KnownLayout, Immutable, Clone, Debug)] #[repr(C)] pub struct NameRecord { raw_names: [u8; RCRD_LEN], diff --git a/anise/src/naif/daf/summary_record.rs b/anise/src/naif/daf/summary_record.rs index 7ca35c28..c3f105b7 100644 --- a/anise/src/naif/daf/summary_record.rs +++ b/anise/src/naif/daf/summary_record.rs @@ -8,11 +8,11 @@ * Documentation: https://nyxspace.com/ */ -use zerocopy::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::NAIFRecord; -#[derive(AsBytes, Clone, Copy, Debug, Default, FromZeroes, FromBytes)] +#[derive(IntoBytes, Clone, Copy, Debug, Default, FromBytes, KnownLayout, Immutable)] #[repr(C)] pub struct SummaryRecord { next_record: f64, diff --git a/anise/src/naif/pck/mod.rs b/anise/src/naif/pck/mod.rs index f1bcef2b..dc3d8e2f 100644 --- a/anise/src/naif/pck/mod.rs +++ b/anise/src/naif/pck/mod.rs @@ -13,7 +13,7 @@ use crate::{ orientations::OrientationError, }; use hifitime::Epoch; -use zerocopy::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; #[cfg(feature = "python")] use pyo3::prelude::*; @@ -22,7 +22,7 @@ use super::daf::DafDataType; #[cfg_attr(feature = "python", pyclass)] #[cfg_attr(feature = "python", pyo3(module = "anise.internals"))] -#[derive(Clone, Copy, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, FromBytes, KnownLayout, Immutable, PartialEq)] #[repr(C)] pub struct BPCSummaryRecord { pub start_epoch_et_s: f64, diff --git a/anise/src/naif/spk/summary.rs b/anise/src/naif/spk/summary.rs index be14be1b..4fa9062c 100644 --- a/anise/src/naif/spk/summary.rs +++ b/anise/src/naif/spk/summary.rs @@ -10,7 +10,7 @@ use core::fmt; use hifitime::{Epoch, TimeUnits}; -use zerocopy::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; #[cfg(feature = "python")] use pyo3::prelude::*; @@ -23,7 +23,7 @@ use crate::{ #[cfg_attr(feature = "python", pyclass)] #[cfg_attr(feature = "python", pyo3(module = "anise.internals"))] -#[derive(Clone, Copy, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq)] +#[derive(Clone, Copy, Debug, Default, IntoBytes, Immutable, KnownLayout, FromBytes, PartialEq)] #[repr(C)] pub struct SPKSummaryRecord { pub start_epoch_et_s: f64,