diff --git a/Cargo.toml b/Cargo.toml index 1c6d4ab..2d60797 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,8 @@ description = "Validation of arbitrary types" repository = "https://github.com/metanomial/vet" license = "MIT OR Apache-2.0" keywords = ["validation"] + +[features] +default = ["std"] +std = ["alloc"] +alloc = [] diff --git a/src/lib.rs b/src/lib.rs index bd3bb36..5ad451f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct Vetted(T); -impl Deref for Vetted { +impl core::ops::Deref for Vetted { type Target = T; fn deref(&self) -> &Self::Target { @@ -107,7 +110,8 @@ impl Vet for Option { } } -impl Vet for Vec { +#[cfg(feature = "alloc")] +impl Vet for alloc::vec::Vec { type VetError = T::VetError; fn is_valid(&self) -> Result<(), Self::VetError> {