♻️ refactor impl Display for Value
							parent
							
								
									72b2d6e656
								
							
						
					
					
						commit
						2bd1ff3d59
					
				
							
								
								
									
										11
									
								
								src/state.rs
								
								
								
								
							
							
						
						
									
										11
									
								
								src/state.rs
								
								
								
								
							| 
						 | 
					@ -245,16 +245,7 @@ impl State {
 | 
				
			||||||
							assert_eq! (*c, 1);
 | 
												assert_eq! (*c, 1);
 | 
				
			||||||
							
 | 
												
 | 
				
			||||||
							let value = r.get (a + 1).unwrap ();
 | 
												let value = r.get (a + 1).unwrap ();
 | 
				
			||||||
							match value {
 | 
												println! ("{}", value);
 | 
				
			||||||
								Value::Nil => println! ("nil"),
 | 
					 | 
				
			||||||
								Value::Boolean (false) => println! ("false"),
 | 
					 | 
				
			||||||
								Value::Boolean (true) => println! ("true"),
 | 
					 | 
				
			||||||
								Value::Float (x) => println! ("{:?}", x),
 | 
					 | 
				
			||||||
								Value::Integer (x) => println! ("{}", x),
 | 
					 | 
				
			||||||
								Value::String (s) => println! ("{}", s),
 | 
					 | 
				
			||||||
								Value::Table (t) => println! ("table: {:?}", std::rc::Rc::as_ptr (t)),
 | 
					 | 
				
			||||||
								_ => unimplemented! (),
 | 
					 | 
				
			||||||
							};
 | 
					 | 
				
			||||||
							
 | 
												
 | 
				
			||||||
							r [a] = r [a + 1].take ();
 | 
												r [a] = r [a + 1].take ();
 | 
				
			||||||
						},
 | 
											},
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										20
									
								
								src/value.rs
								
								
								
								
							
							
						
						
									
										20
									
								
								src/value.rs
								
								
								
								
							| 
						 | 
					@ -4,6 +4,7 @@ use std::{
 | 
				
			||||||
		PartialEq,
 | 
							PartialEq,
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	collections::HashMap,
 | 
						collections::HashMap,
 | 
				
			||||||
 | 
						fmt,
 | 
				
			||||||
	rc::Rc,
 | 
						rc::Rc,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,6 +42,25 @@ impl Default for Value {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl fmt::Display for Value {
 | 
				
			||||||
 | 
						fn fmt (&self, f: &mut fmt::Formatter) -> fmt::Result {
 | 
				
			||||||
 | 
							match self {
 | 
				
			||||||
 | 
								Value::Nil => write! (f, "nil"),
 | 
				
			||||||
 | 
								Value::Boolean (false) => write! (f, "false"),
 | 
				
			||||||
 | 
								Value::Boolean (true) => write! (f, "true"),
 | 
				
			||||||
 | 
								Value::Float (x) => write! (f, "{:?}", x),
 | 
				
			||||||
 | 
								Value::Integer (x) => write! (f, "{}", x),
 | 
				
			||||||
 | 
								Value::String (s) => write! (f, "{}", s),
 | 
				
			||||||
 | 
								Value::Table (t) => write! (f, "table: {:?}", std::rc::Rc::as_ptr (t)),
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								Value::BogusArg (_) => write! (f, "BogusArg"),
 | 
				
			||||||
 | 
								Value::BogusClosure (_) => write! (f, "BogusClosure"),
 | 
				
			||||||
 | 
								Value::BogusEnv (_) => write! (f, "BogusEnv"),
 | 
				
			||||||
 | 
								Value::BogusPrint => write! (f, "BogusPrint"),
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl From <String> for Value {
 | 
					impl From <String> for Value {
 | 
				
			||||||
	fn from (x: String) -> Self {
 | 
						fn from (x: String) -> Self {
 | 
				
			||||||
		Self::String (x.into ())
 | 
							Self::String (x.into ())
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue