Skip to content

Commit

Permalink
no-std support will be done in #20
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherRabotin committed Jun 22, 2023
1 parent e2a2975 commit b2bdcb5
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 15 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ polars = {version = "0.30", features = ["lazy", "parquet"]}
rayon = "1.7"

[features]
default = ["std", "validation"]
std = []
default = ["validation"]
validation = [] # Enabling this flag significantly reduces compilation times due to Arrow and Polars.

[profile.bench]
Expand Down
2 changes: 0 additions & 2 deletions src/bin/anise/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use anise::cli::inspect::{BpcRow, SpkRow};
use anise::cli::CliErrors;
use anise::file_mmap;
use anise::naif::daf::{FileRecord, NAIFRecord, NAIFSummaryRecord};
#[cfg(feature = "std")]
use anise::naif::kpl::parser::convert_tpc;
use anise::prelude::*;
use anise::structure::dataset::{DataSet, DataSetType};
Expand All @@ -20,7 +19,6 @@ use zerocopy::FromBytes;

const LOG_VAR: &str = "ANISE_LOG";

#[cfg(feature = "std")]
fn main() -> Result<(), CliErrors> {
if var(LOG_VAR).is_err() {
set_var(LOG_VAR, "INFO");
Expand Down
8 changes: 3 additions & 5 deletions src/naif/daf/daf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ use core::hash::Hash;
use hifitime::Epoch;
use log::{error, trace, warn};
use std::marker::PhantomData;
#[cfg(feature = "std")]

use zerocopy::AsBytes;
use zerocopy::{FromBytes, LayoutVerified};

// Thanks ChatGPT for the idea !
#[cfg(feature = "std")]

macro_rules! io_imports {
() => {
use std::fs::File;
Expand All @@ -31,7 +31,6 @@ macro_rules! io_imports {
};
}

#[cfg(feature = "std")]
io_imports!();

pub(crate) const RCRD_LEN: usize = 1024;
Expand Down Expand Up @@ -280,7 +279,7 @@ impl<R: NAIFSummaryRecord> DAF<R> {
}

/// Writes the contents of this DAF file to a new location.
#[cfg(feature = "std")]
pub fn persist<P: AsRef<Path>>(&self, path: P) -> IoResult<()> {
let mut fs = File::create(path)?;

Expand Down Expand Up @@ -308,7 +307,6 @@ impl<R: NAIFSummaryRecord> DAF<R> {
fs.write_all(&self.bytes[self.file_record.fwrd_idx() * (2 * RCRD_LEN)..])
}

#[cfg(feature = "std")]
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self, AniseError> {
let mut buf = Vec::new();
let mut file = File::open(path).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/naif/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

pub mod daf;
#[cfg(feature = "std")]

pub mod kpl;
pub mod pck;
pub mod spk;
Expand Down
4 changes: 1 addition & 3 deletions src/structure/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use core::marker::PhantomData;
use der::{asn1::OctetStringRef, Decode, Encode, Reader, Writer};
use log::{error, trace};

#[cfg(feature = "std")]
macro_rules! io_imports {
() => {
use std::fs::File;
Expand All @@ -29,7 +28,6 @@ macro_rules! io_imports {
};
}

#[cfg(feature = "std")]
io_imports!();

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
Expand Down Expand Up @@ -256,7 +254,7 @@ impl<'a, T: DataSetT<'a>, const ENTRIES: usize> DataSet<'a, T, ENTRIES> {

/// Saves this dataset to the provided file
/// If overwrite is set to false, and the filename already exists, this function will return an error.
#[cfg(feature = "std")]
pub fn save_as(&self, filename: PathBuf, overwrite: bool) -> Result<(), AniseError> {
use log::{info, warn};

Expand Down
1 change: 0 additions & 1 deletion tests/context/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(feature = "std")]
#[test]
fn test_load_ctx() {
// Start bycreating the ANISE planetary data
Expand Down
2 changes: 1 addition & 1 deletion tests/naif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn test_spk_load_bytes() {
}

// The `load` function copies the bytes, so it's only available with std
#[cfg(feature = "std")]

#[test]
fn test_spk_rename_summary() {
if pretty_env_logger::try_init().is_err() {
Expand Down

0 comments on commit b2bdcb5

Please sign in to comment.