pub enum JSONDrawAction {
DrawForward {
dist: f64,
},
MoveForward {
dist: f64,
},
RotateCW {
numerator: isize,
denominator: usize,
},
Push {
stack: usize,
},
Pop {
stack: usize,
},
Null,
}Expand description
Represents a DrawAction, coming from JSON deserialization.
§Examples
use std::collections::HashMap;
use std::f64::consts::PI;
use l_system_fractals::parse_files::JSONDrawAction;
use l_system_fractals::rules::DrawAction;
use l_system_fractals::num_validity::AlmostEq;
let json_string = r#"{
"A": {"type": "RotateCW", "numerator": 1, "denominator": 4},
"B": {"type": "Push", "stack": 0}
}"#;
let actions: HashMap<char, JSONDrawAction> = serde_json::from_str(&json_string).unwrap();
let action_a: DrawAction = actions.get(&'A')
.unwrap()
.to_owned()
.try_into()
.unwrap();
assert!(
action_a.almost_eq(
&DrawAction::RotateCW(0.25 * PI),
0.001
)
);
let action_b: DrawAction = actions.get(&'B')
.unwrap()
.to_owned()
.try_into()
.unwrap();
assert!(
action_b.almost_eq(
&DrawAction::Push(0),
0.001
)
);Variants§
DrawForward
Deserializable version of DrawAction::DrawForward.
§Example
use std::collections::HashMap;
use l_system_fractals::parse_files::JSONDrawAction;
use l_system_fractals::rules::DrawAction;
use l_system_fractals::num_validity::AlmostEq;
let json_string = r#"{ "type": "DrawForward", "dist": 1.5 }"#;
let json_df: JSONDrawAction = serde_json::from_str(json_string).unwrap();
let df: DrawAction = json_df.try_into().unwrap();
assert!(df.almost_eq(&DrawAction::DrawForward(1.5), 0.001));MoveForward
Deserializable version of DrawAction::MoveForward.
§Example
use std::collections::HashMap;
use l_system_fractals::parse_files::JSONDrawAction;
use l_system_fractals::rules::DrawAction;
use l_system_fractals::num_validity::AlmostEq;
let json_string = r#"{ "type": "MoveForward", "dist": 1.5 }"#;
let json_mf: JSONDrawAction = serde_json::from_str(json_string).unwrap();
let mf: DrawAction = json_mf.try_into().unwrap();
assert!(mf.almost_eq(&DrawAction::MoveForward(1.5), 0.001));RotateCW
Deserializable version of DrawAction::RotateCW.
§Example
use std::collections::HashMap;
use std::f64::consts::PI;
use l_system_fractals::parse_files::JSONDrawAction;
use l_system_fractals::rules::DrawAction;
use l_system_fractals::num_validity::AlmostEq;
let json_string = r#"{ "type": "RotateCW", "numerator": 1, "denominator": 4 }"#;
let json_rc: JSONDrawAction = serde_json::from_str(json_string).unwrap();
let rc: DrawAction = json_rc.try_into().unwrap();
assert!(rc.almost_eq(&DrawAction::RotateCW(0.25 * PI), 0.001));Fields
Push
Deserializable version of DrawAction::Push.
§Example
use std::collections::HashMap;
use l_system_fractals::parse_files::JSONDrawAction;
use l_system_fractals::rules::DrawAction;
let json_string = r#"{ "type": "Push", "stack": 3 }"#;
let json_p: JSONDrawAction = serde_json::from_str(json_string).unwrap();
let p: DrawAction = json_p.try_into().unwrap();
assert_eq!(p, DrawAction::Push(3));Pop
Deserializable version of DrawAction::Pop.
§Example
use std::collections::HashMap;
use l_system_fractals::parse_files::JSONDrawAction;
use l_system_fractals::rules::DrawAction;
let json_string = r#"{ "type": "Pop", "stack": 3 }"#;
let json_p: JSONDrawAction = serde_json::from_str(json_string).unwrap();
let p: DrawAction = json_p.try_into().unwrap();
assert_eq!(p, DrawAction::Pop(3));Null
Deserializable version of DrawAction::Null.
§Example
use std::collections::HashMap;
use l_system_fractals::parse_files::JSONDrawAction;
use l_system_fractals::rules::DrawAction;
let json_string = r#"{ "type": "Null"}"#;
let json_n: JSONDrawAction = serde_json::from_str(json_string).unwrap();
let n: DrawAction = json_n.try_into().unwrap();
assert_eq!(n, DrawAction::Null);Trait Implementations§
Source§impl AlmostEq for JSONDrawAction
impl AlmostEq for JSONDrawAction
Source§impl Clone for JSONDrawAction
impl Clone for JSONDrawAction
Source§fn clone(&self) -> JSONDrawAction
fn clone(&self) -> JSONDrawAction
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for JSONDrawAction
impl Debug for JSONDrawAction
Source§impl<'de> Deserialize<'de> for JSONDrawAction
impl<'de> Deserialize<'de> for JSONDrawAction
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for JSONDrawAction
impl PartialEq for JSONDrawAction
Source§impl TryFrom<JSONDrawAction> for DrawAction
impl TryFrom<JSONDrawAction> for DrawAction
Source§type Error = LSystemError
type Error = LSystemError
The type returned in the event of a conversion error.
impl Copy for JSONDrawAction
impl StructuralPartialEq for JSONDrawAction
Auto Trait Implementations§
impl Freeze for JSONDrawAction
impl RefUnwindSafe for JSONDrawAction
impl Send for JSONDrawAction
impl Sync for JSONDrawAction
impl Unpin for JSONDrawAction
impl UnwindSafe for JSONDrawAction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more