Comments (3)
Can you give me a complete program? That one is missing some definitions. (I changed some stuff to make it compile but the test ran without a problem.)
from rpds.
Code at end of comment. I only want to implement PartialEq
so I can perform unit tests for equality tests. Now that they're all in the one file, I'm getting a new error (maybe because of the double impl for the HVal
trait and the HDict
trait?)
What I find strange is that originally, the first two commented out assert
s worked.
In my main code where these components are split into other modules:
New Error
thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Aborted (core dumped)
Code
extern crate rpds;
use std::fmt::Debug;
use std::any::{Any,TypeId};
use rpds::HashTrieMap;
use rpds::map::hash_trie_map::Iter;
pub trait HVal: Any + Debug {
fn to_zinc(&self) -> String;
fn to_string(&self) -> String {
self.to_zinc()
}
fn _get_type_id(&self) -> TypeId {
TypeId::of::<Self>()
}
}
///*
impl Eq for HVal {}
impl PartialEq for HVal {
fn eq(&self, other: &Self) -> bool {
//self.tr_eq(other)
match self._get_type_id() == other._get_type_id() {
true => self == other,
false => false
}
}
}
//*/
pub type HBool = bool;
impl HVal for HBool {
fn to_zinc(&self) -> String {
match *self {
true => "T".to_string(),
false => "F".to_string(),
}
}
}
type ContainedHval = Box<HVal>;
#[derive(Clone,Debug)]
pub struct HDict(HashTrieMap<String, ContainedHval>);
impl HVal for HDict {
fn to_zinc(&self) -> String {
"Not implemented!".to_string()
}
}
///*
impl Eq for HDict {}
impl PartialEq for HDict {
fn eq(&self, other: &Self) -> bool {
if self.0.size() != other.0.size() {
return false;
}
for (k,v) in self.0.iter() {
let tmp = match other.0.get(k) {
Some(ov) => **v == **ov,
None => false
};
if !tmp {
return false;
}
}
true
}
}
//*/
impl HDict {
pub fn new() -> HDict {
HDict(HashTrieMap::new())
}
fn has(&self, name: &String) -> HBool {
self.0.contains_key(name)
}
fn is_empty(&self) -> HBool {
self.0.is_empty()
}
fn missing(&self, name: &String) -> HBool {
!self.0.contains_key(name)
}
pub fn iter(&self) -> Iter<String, ContainedHval> {
self.0.iter()
}
fn insert(&mut self, name: &String, value: ContainedHval) -> Self {
HDict(self.0.insert(name.clone(),value))
}
}
fn main() {
let a = HDict::new();
let b = HDict::new().insert(&"Hello".to_owned(),Box::new(true));
//assert_ne!(a,a.clone().insert(&"Hello".to_owned(),Box::new(true)));
//assert_eq!(a,HDict::new());
assert_eq!(
b.clone(),
HDict::new().insert(&"Hello".to_owned(),Box::new(true))
);
}
from rpds.
That's because HVal::eq()
calls itself endlessly:
impl PartialEq for HVal {
fn eq(&self, other: &Self) -> bool {
match self._get_type_id() == other._get_type_id() {
true => self == other, // !!! This is a recursive call
false => false
}
}
}
from rpds.
Related Issues (20)
- Add feature to provide Trace and Finalize impls for https://github.com/Manishearth/rust-gc
- HAMP vs CHAMP
- Implement .range_index() for RedBlackTreeMap/RedBlackTreeSet HOT 1
- Memory Usage for Debugging HOT 4
- Is this stable for handling large scale data (> 10^8) HOT 1
- Finger Trees HOT 1
- faster slicing for vectors? HOT 3
- `RedBlackTreeSet`'s docs mention non-existent `get` operation HOT 2
- Consider re-exporting archery items
- Consider providing a .pop_with_value() helper on Stack and List
- Support custom allocator HOT 1
- Serializing multiple instances efficiently HOT 1
- extract variants of remove on HashTrieMap and RedBlackTreeMap
- Add a "feature" to remove _mut methods HOT 4
- Opening doc. HOT 1
- Non-empty containers HOT 1
- sparse_array_usize test failures on i686 HOT 2
- FYI: Python bindings / Minor README question HOT 2
- How can a data structure be persisted to a file efficiently? HOT 1
- Copy trait for HashTrieMap ? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rpds.