Enum sfv::BareItem

source ·
pub enum BareItem {
    Decimal(Decimal),
    Integer(i64),
    String(String),
    ByteSeq(Vec<u8>),
    Boolean(bool),
    Token(String),
}
Expand description

BareItem type is used to construct Items or Parameters values.

Variants§

§

Decimal(Decimal)

Decimal number

§

Integer(i64)

Integer number

§

String(String)

§

ByteSeq(Vec<u8>)

§

Boolean(bool)

§

Token(String)

Implementations§

source§

impl BareItem

source

pub fn as_decimal(&self) -> Option<Decimal>

If BareItem is a decimal, returns Decimal, otherwise returns None.

let decimal_number = Decimal::from_f64(415.566).unwrap();
let bare_item: BareItem = decimal_number.into();
assert_eq!(bare_item.as_decimal().unwrap(), decimal_number);
source

pub fn as_int(&self) -> Option<i64>

If BareItem is an integer, returns i64, otherwise returns None.

let bare_item: BareItem = 100.into();
assert_eq!(bare_item.as_int().unwrap(), 100);
source

pub fn as_str(&self) -> Option<&str>

If BareItem is String, returns &str, otherwise returns None.

let bare_item = BareItem::String("foo".into());
assert_eq!(bare_item.as_str().unwrap(), "foo");
source

pub fn as_byte_seq(&self) -> Option<&Vec<u8>>

If BareItem is a ByteSeq, returns &Vec<u8>, otherwise returns None.

let bare_item = BareItem::ByteSeq("foo".to_owned().into_bytes());
assert_eq!(bare_item.as_byte_seq().unwrap().as_slice(), "foo".as_bytes());
source

pub fn as_bool(&self) -> Option<bool>

If BareItem is a Boolean, returns bool, otherwise returns None.

let bare_item = BareItem::Boolean(true);
assert_eq!(bare_item.as_bool().unwrap(), true);
source

pub fn as_token(&self) -> Option<&str>

If BareItem is a Token, returns &str, otherwise returns None.

use sfv::BareItem;

let bare_item = BareItem::Token("*bar".into());
assert_eq!(bare_item.as_token().unwrap(), "*bar");

Trait Implementations§

source§

impl Clone for BareItem

source§

fn clone(&self) -> BareItem

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for BareItem

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Decimal> for BareItem

source§

fn from(item: Decimal) -> Self

Converts Decimal into BareItem::Decimal.

let decimal_number = Decimal::from_f64(48.01).unwrap();
let bare_item: BareItem = decimal_number.into();
assert_eq!(bare_item.as_decimal().unwrap(), decimal_number);
source§

impl From<i64> for BareItem

source§

fn from(item: i64) -> Self

Converts i64 into BareItem::Integer.

let bare_item: BareItem = 456.into();
assert_eq!(bare_item.as_int().unwrap(), 456);
source§

impl PartialEq for BareItem

source§

fn eq(&self, other: &BareItem) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for BareItem

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.