Enable use in no_std environments

This commit is contained in:
Nettika 2022-07-04 22:25:13 -07:00
parent 542652f305
commit e7f317cc52
2 changed files with 12 additions and 3 deletions

View file

@ -7,3 +7,8 @@ description = "Validation of arbitrary types"
repository = "https://github.com/metanomial/vet" repository = "https://github.com/metanomial/vet"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
keywords = ["validation"] keywords = ["validation"]
[features]
default = ["std"]
std = ["alloc"]
alloc = []

View file

@ -62,13 +62,16 @@
//! } //! }
//! ``` //! ```
use core::ops::Deref; #![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "alloc")]
extern crate alloc;
/// A wrapper around a validated instance /// A wrapper around a validated instance
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Vetted<T>(T); pub struct Vetted<T>(T);
impl<T> Deref for Vetted<T> { impl<T> core::ops::Deref for Vetted<T> {
type Target = T; type Target = T;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
@ -107,7 +110,8 @@ impl<T: Vet> Vet for Option<T> {
} }
} }
impl<T: Vet> Vet for Vec<T> { #[cfg(feature = "alloc")]
impl<T: Vet> Vet for alloc::vec::Vec<T> {
type VetError = T::VetError; type VetError = T::VetError;
fn is_valid(&self) -> Result<(), Self::VetError> { fn is_valid(&self) -> Result<(), Self::VetError> {