-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support no_std (#544) * Simpler clippy check (no features in safetensors really). --------- Co-authored-by: Nicolas Patry <[email protected]>
- Loading branch information
Showing
5 changed files
with
82 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,43 @@ | ||
#![deny(missing_docs)] | ||
#![doc = include_str!("../README.md")] | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
pub mod slice; | ||
pub mod tensor; | ||
pub use tensor::{serialize, serialize_to_file, Dtype, SafeTensorError, SafeTensors, View}; | ||
/// serialize_to_file only valid in std | ||
#[cfg(feature = "std")] | ||
pub use tensor::serialize_to_file; | ||
pub use tensor::{serialize, Dtype, SafeTensorError, SafeTensors, View}; | ||
|
||
#[cfg(feature = "alloc")] | ||
#[macro_use] | ||
extern crate alloc; | ||
|
||
#[cfg(all(feature = "std", feature = "alloc"))] | ||
compile_error!("must choose either the `std` or `alloc` feature, but not both."); | ||
#[cfg(all(not(feature = "std"), not(feature = "alloc")))] | ||
compile_error!("must choose either the `std` or `alloc` feature"); | ||
|
||
/// A facade around all the types we need from the `std`, `core`, and `alloc` | ||
/// crates. This avoids elaborate import wrangling having to happen in every | ||
/// module. | ||
mod lib { | ||
#[cfg(not(feature = "std"))] | ||
mod no_stds { | ||
pub use alloc::borrow::Cow; | ||
pub use alloc::string::{String, ToString}; | ||
pub use alloc::vec::Vec; | ||
pub use hashbrown::HashMap; | ||
} | ||
#[cfg(feature = "std")] | ||
mod stds { | ||
pub use std::borrow::Cow; | ||
pub use std::collections::HashMap; | ||
pub use std::string::{String, ToString}; | ||
pub use std::vec::Vec; | ||
} | ||
/// choose std or no_std to export by feature flag | ||
#[cfg(not(feature = "std"))] | ||
pub use no_stds::*; | ||
#[cfg(feature = "std")] | ||
pub use stds::*; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters