Enable use in no_std environments
This commit is contained in:
parent
33ca42a731
commit
283bce1f16
2 changed files with 12 additions and 3 deletions
|
|
@ -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 = []
|
||||||
|
|
|
||||||
10
src/lib.rs
10
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
|
/// 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> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue