[−][src]Enum edn_rs::edn::Edn
EdnType
is an Enum with possible values for an EDN type
Symbol and Char are not yet implemented
String implementation of Edn can be obtained with .to_string()
Variants
Vector(Vector)
Set(Set)
Map(Map)
List(List)
Key(String)
Symbol(String)
Str(String)
Int(isize)
UInt(usize)
Double(Double)
Rational(String)
Char(char)
Bool(bool)
Implementations
impl Edn
[src]
pub fn to_float(&self) -> Option<f64>
[src]
to_float
takes an Edn
and returns an Option<f64>
with its value. Most types return None
use edn_rs::edn::{Edn, Vector}; let key = Edn::Key(String::from("1234")); let q = Edn::Rational(String::from("3/4")); let i = Edn::Int(12isize); assert_eq!(Edn::Vector(Vector::empty()).to_float(), None); assert_eq!(key.to_float().unwrap(),1234f64); assert_eq!(q.to_float().unwrap(), 0.75f64); assert_eq!(i.to_float().unwrap(), 12f64);
pub fn to_int(&self) -> Option<isize>
[src]
to_int
takes an Edn
and returns an Option<isize>
with its value. Most types return None
use edn_rs::edn::{Edn, Vector}; let key = Edn::Key(String::from("1234")); let q = Edn::Rational(String::from("3/4")); let f = Edn::Double(12.3f64.into()); assert_eq!(Edn::Vector(Vector::empty()).to_float(), None); assert_eq!(key.to_int().unwrap(),1234isize); assert_eq!(q.to_int().unwrap(), 1isize); assert_eq!(f.to_int().unwrap(), 12isize);
pub fn to_uint(&self) -> Option<usize>
[src]
Similar to to_int
but returns an Option<usize>
pub fn to_bool(&self) -> Option<bool>
[src]
to_bool
takes an Edn
and returns an Option<bool>
with its value. Most types return None
use edn_rs::edn::{Edn}; let b = Edn::Bool(true); let s = Edn::Str("true".to_string()); let symbol = Edn::Symbol("false".to_string()); assert_eq!(b.to_bool().unwrap(),true); assert_eq!(s.to_bool().unwrap(),true); assert_eq!(symbol.to_bool().unwrap(),false);
pub fn to_vec(&self) -> Option<Vec<String>>
[src]
to_vec
converts Edn
types Vector
and List
into an Option<Vec<String>>
.
Type String was selected because it is the current way to mix floats, integers and Strings.
pub fn get<I: Index>(&self, index: I) -> Option<&Edn>
[src]
Index into a EDN vector, list, set or map. A string index can be used to access a value in a map, and a usize index can be used to access an element of a seqs.
Returns None
if the type of self
does not match the type of the
index, for example if the index is a string and self
is a seq or a
number. Also returns None
if the given key does not exist in the map
or the given index is not within the bounds of the seq.
#[macro_use] extern crate edn_rs; use edn_rs::edn::{Edn, Map, Vector}; fn main() { let edn = edn!([ 1 1.2 3 {false :f nil 3/4}]); assert_eq!(edn[1], edn!(1.2)); assert_eq!(edn.get(1).unwrap(), &edn!(1.2)); assert_eq!(edn[3]["false"], edn!(:f)); assert_eq!(edn[3].get("false").unwrap(), &Edn::Key("f".to_string())); }
pub fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut Edn>
[src]
Mutably index into a EDN vector, set, list or map. A string index can be used to access a value in a map, and a usize index can be used to access an element of a seq.
Returns None
if the type of self
does not match the type of the
index, for example if the index is a string and self
is a seq or a
number. Also returns None
if the given key does not exist in the map
or the given index is not within the bounds of the seq.
#[macro_use] extern crate edn_rs; use edn_rs::edn::{Edn, Map, Vector}; fn main() { let mut edn = edn!([ 1 1.2 3 {false :f nil 3/4}]); assert_eq!(edn[1], edn!(1.2)); assert_eq!(edn.get_mut(1).unwrap(), &edn!(1.2)); assert_eq!(edn[3]["false"], edn!(:f)); assert_eq!(edn[3].get_mut("false").unwrap(), &Edn::Key("f".to_string())); }
pub fn iter(&self) -> Option<Iter<Edn>>
[src]
iter
returns am Option<Iter<Edn>>
with Some
for types Edn::Vector
and Edn::List
Other types return None
use edn_rs::{Edn, Vector}; fn main() { let v = Edn::Vector(Vector::new(vec![Edn::Int(5), Edn::Int(6), Edn::Int(7)])); let sum = v.iter().unwrap().filter(|e| e.to_int().is_some()).map(|e| e.to_int().unwrap()).sum(); assert_eq!(18isize, sum); }
pub fn set_iter(&self) -> Option<Iter<Edn>>
[src]
set_iter
returns am Option<btree_set::Iter<Edn>>
with Some
for type Edn::Set
Other types return None
pub fn map_iter(&self) -> Option<Iter<String, Edn>>
[src]
map_iter
returns am Option<btree_map::Iter<String, Edn>>
with Some
for type Edn::Map
Other types return None
Trait Implementations
impl Clone for Edn
[src]
impl Debug for Edn
[src]
impl Display for Edn
[src]
impl Eq for Edn
[src]
impl FromStr for Edn
[src]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl Hash for Edn
[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<I> Index<I> for Edn where
I: Index,
[src]
I: Index,
impl<I> IndexMut<I> for Edn where
I: Index,
[src]
I: Index,
impl Ord for Edn
[src]
fn cmp(&self, other: &Edn) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<Edn> for Edn
[src]
impl PartialOrd<Edn> for Edn
[src]
fn partial_cmp(&self, other: &Edn) -> Option<Ordering>
[src]
fn lt(&self, other: &Edn) -> bool
[src]
fn le(&self, other: &Edn) -> bool
[src]
fn gt(&self, other: &Edn) -> bool
[src]
fn ge(&self, other: &Edn) -> bool
[src]
impl StructuralEq for Edn
[src]
impl StructuralPartialEq for Edn
[src]
Auto Trait Implementations
impl RefUnwindSafe for Edn
impl Send for Edn
impl Sync for Edn
impl Unpin for Edn
impl UnwindSafe for Edn
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> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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>,