Hi, I've recently started hacking a bit on Servo. I'm new to Rust, and so I'm complaining about the first thing that bit me. :-)
In the Servo DOM, we've got this trait called |CacheableWrapper|, which I've recently renamed to |Reflectable|. This trait is implemented by most DOM objects, and is the mechanism by which we reach the JS reflection of a rust object. The |Reflectable| trait has the following method: |fn reflector(&mut self) -> &mut Reflector;|. Reflector has two methods: pub fn get_jsobject(&self) -> *JSObject pub fn set_jsobject(&mut self, object: *JSObject) If I have some immutable Rust DOM object, it would be great if I could invoke something like the following: dom_object.reflector().get_ jsobject(). But currently, I have to force the thing to be mutable just to access the Reflector, even if, eventually, I just want to invoke an immutable method on the resulting Reflector. I would love to be able to declare a companion |fn reflector(&self) -> &Reflector;|, but Rust doesn't seem to support function overloads. Ms2ger suggests adding mut_reflector variants of all the methods we might want to invoke in a mutable fashion. But this kind of name-mangling seems like a workaround for a problem that the language should solve, especially given the heavy emphasis on immutability. Are there any plans for dealing with this problem in the language? If not, are we designing things wrong in Servo, or should Rust programs prepend |mut_| to any mutable method that might conceivably have an immutable variant? It seems like we could also solve this problem by ditching the reflector() getter and accessing the |reflector| property directly. But I don't see a way to make that work with Traits. Cheers, bholley _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
