Enum edn_rs::edn::Edn[][src]

pub enum Edn {
Show 19 variants Tagged(StringBox<Edn>), 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), Inst(String), Uuid(String), NamespacedMap(StringMap), Nil, Empty,
}
Expand description

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

Tagged(StringBox<Edn>)

Tuple Fields

0: String
1: Box<Edn>

Vector(Vector)

Tuple Fields

0: Vector

Set(Set)

Tuple Fields

0: Set

Map(Map)

Tuple Fields

0: Map

List(List)

Tuple Fields

0: List

Key(String)

Tuple Fields

0: String

Symbol(String)

Tuple Fields

0: String

Str(String)

Tuple Fields

0: String

Int(isize)

Tuple Fields

0: isize

UInt(usize)

Tuple Fields

0: usize

Double(Double)

Tuple Fields

0: Double

Rational(String)

Tuple Fields

0: String

Char(char)

Tuple Fields

0: char

Bool(bool)

Tuple Fields

0: bool

Inst(String)

Tuple Fields

0: String

Uuid(String)

Tuple Fields

0: String

NamespacedMap(StringMap)

Tuple Fields

0: String
1: Map

Nil

Empty

Implementations

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);

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);

Similar to to_int but returns an Option<usize>

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);

to_char takes an Edn and returns an Option<char> with its value. Most types return None

use edn_rs::edn::{Edn};

let c = Edn::Char('c');
let symbol = Edn::Symbol("false".to_string());

assert_eq!(c.to_char().unwrap(),'c');
assert_eq!(symbol.to_char(), None);

to_vec converts Edn types Vector, List and Set into an Option<Vec<String>>. Type String was selected because it is the current way to mix floats, integers and Strings.

to_int_vec converts Edn types Vector List and Set into an Option<Vec<isize>>. All elements of this Edn structure should be of the same type

to_uint_vec converts Edn types Vector List and Set into an Option<Vec<usize>>. All elements of this Edn structure should be of the same type

to_float_vec converts Edn types Vector List and Set into an Option<Vec<f64>>. All elements of this Edn structure should be of the same type

to_bool_vec converts Edn types Vector List and Set into an Option<Vec<bool>>. All elements of this Edn structure should be of the same type

std::fmt::Debug to_debug is a wrapper of format!("{:?}", &self) for &Edn.

use edn_rs::edn::{Edn, Vector};

let edn = Edn::Vector(Vector::new(vec![Edn::Int(5), Edn::Int(6), Edn::Int(7)]));
let expected = "Vector(Vector([Int(5), Int(6), Int(7)]))";

assert_eq!(edn.to_debug(), expected);

While to_string returns a valid edn:

use edn_rs::edn::{Edn, Vector};

let edn = Edn::Vector(Vector::new(vec![Edn::Int(5), Edn::Int(6), Edn::Int(7)]));
let expected = "[5, 6, 7, ]";

assert_eq!(edn.to_string(), expected);

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()));
}

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()));
}

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);
}

set_iter returns am Option<btree_set::Iter<Edn>> with Some for type Edn::Set Other types return None

map_iter returns am Option<btree_map::Iter<String, Edn>> with Some for type Edn::Map Other types return None

to_str_uuid returns am Option<String> with Some containing the string representing the UUID for type Edn::Uuid Other types return None

to_str_INST returns am Option<String> with Some containing the string representing the instant for type Edn::Inst Other types return None

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Parses a &str that contains an Edn into Result<Edn, EdnError>

The associated error which can be returned from parsing.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.