[−][src]Enum jail::param::Value
An enum representing the value of a parameter.
Variants
Int(c_int)
String(String)
S64(i64)
Uint(c_uint)
Long(c_long)
Ulong(c_ulong)
U64(u64)
U8(u8)
U16(u16)
S8(i8)
S16(i16)
S32(i32)
U32(u32)
Represent a list of IPv4 addresses.
Example
use jail::param::Value; let rfc1918 = Value::Ipv4Addrs(vec![ "10.0.0.0".parse().unwrap(), "172.16.0.0".parse().unwrap(), "192.168.0.0".parse().unwrap(), ]);
Represent a list of IPv6 addresses.
Example
use jail::param::Value; let all_nodes = Value::Ipv6Addrs(vec![ "ff01::1".parse().unwrap(), "ff02::1".parse().unwrap(), ]);
Implementations
impl Value
[src]
pub fn get_type(&self) -> Type
[src]
Get the type of this value
Examples
use jail::param::{Type, Value}; assert_eq!(Value::Int(42).get_type(), Type::Int);
Types allow for convenient checks:
use jail::param::Value; assert!(Value::Int(42).get_type().is_signed());
pub fn as_bytes(self) -> Result<Vec<u8>, JailError>
[src]
Format the value into a vector of bytes as expected by the jail parameter API.
pub fn unpack_ipv4(self) -> Result<Vec<Ipv4Addr>, JailError>
[src]
Attempt to unpack the Vector of IPv4 addresses contained in this value
Example
use jail::param::Value; use std::net; let ips = rfc1918 .unpack_ipv4() .expect("could not unwrap RFC1918 IP Addresses"); assert_eq!(ips[0], net::Ipv4Addr::new(10,0,0,0));
Attempting to unwrap a different value will fail:
use jail::param::Value; let not_ipv4_addrs = Value::U8(42); not_ipv4_addrs.unpack_ipv4().unwrap();
pub fn unpack_ipv6(self) -> Result<Vec<Ipv6Addr>, JailError>
[src]
Attempt to unpack the Vector of IPv4 addresses contained in this value
Example
use jail::param::Value; use std::net; let ips = all_nodes .unpack_ipv6() .expect("could not unwrap 'All Nodes' IPv6 Addresses"); assert_eq!(ips[0], net::Ipv6Addr::new(0xff01, 0, 0, 0, 0, 0, 0, 1))
Attempting to unwrap a different value will fail:
use jail::param::Value; rfc1918.unpack_ipv6().unwrap();
pub fn unpack_string(self) -> Result<String, JailError>
[src]
Attempt to unpack a String value contained in this parameter Value.
use jail::param::Value; let value = Value::String("foobar".into()); assert_eq!( value.unpack_string().unwrap(), "foobar".to_string() );
Attempting to unwrap a different value will fail:
use jail::param::Value; let not_a_string = Value::U8(42); not_a_string.unpack_string().unwrap();
pub fn unpack_u64(self) -> Result<u64, JailError>
[src]
Attempt to unpack any unsigned integer Value into a 64 bit unsigned integer.
Shorter values will be zero-extended as appropriate.
Example
use jail::param::Value; assert_eq!(Value::U64(64u64).unpack_u64().unwrap(), 64u64); assert_eq!(Value::U32(32u32).unpack_u64().unwrap(), 32u64); assert_eq!(Value::U16(16u16).unpack_u64().unwrap(), 16u64); assert_eq!(Value::U8(8u8).unpack_u64().unwrap(), 8u64); assert_eq!(Value::Uint(1234).unpack_u64().unwrap(), 1234u64); assert_eq!(Value::Ulong(42).unpack_u64().unwrap(), 42u64); // Everything else should fail. assert!(Value::String("1234".into()).unpack_u64().is_err()); assert!(Value::S64(64i64).unpack_u64().is_err());
pub fn unpack_i64(self) -> Result<i64, JailError>
[src]
Attempt to unpack any Value containing a signed integer or unsigned integer shorter than 64 bits into a 64 bit unsigned integer.
Shorter values will be zero-extended as appropriate.
Example
use jail::param::Value; assert_eq!(Value::S64(-64i64).unpack_i64().unwrap(), -64i64); assert_eq!(Value::S32(-32i32).unpack_i64().unwrap(), -32i64); assert_eq!(Value::S16(-16i16).unpack_i64().unwrap(), -16i64); assert_eq!(Value::S8(-8i8).unpack_i64().unwrap(), -8i64); assert_eq!(Value::U32(32u32).unpack_i64().unwrap(), 32i64); assert_eq!(Value::U16(16u16).unpack_i64().unwrap(), 16i64); assert_eq!(Value::U8(8u8).unpack_i64().unwrap(), 8i64); assert_eq!(Value::Uint(1234).unpack_i64().unwrap(), 1234i64); assert_eq!(Value::Int(-1234).unpack_i64().unwrap(), -1234i64); assert_eq!(Value::Long(-42).unpack_i64().unwrap(), -42i64); // Everything else should fail. assert!(Value::String("1234".into()).unpack_i64().is_err()); assert!(Value::U64(64u64).unpack_i64().is_err());
Trait Implementations
impl Clone for Value
[src]
impl Debug for Value
[src]
impl Eq for Value
[src]
impl<'_enum> From<&'_enum Value> for Type
[src]
impl From<Value> for Type
[src]
impl Hash for Value
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl PartialEq<Value> for Value
[src]
impl StructuralEq for Value
[src]
impl StructuralPartialEq for Value
[src]
Auto Trait Implementations
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,