Why I’m dropping Rust
Rust seems to be a poor match for the way the author wishes to solve this particular problem. That doesn&#x27;t mean that their design is wrong, or that Rust is wrong, but it does mean that mixing the two would require rethinking parts of the design.<p>&gt; So a trait can define abstract functions, but can&#x27;t access any underlying fields.<p>In Rust, a trait is a purely abstract interface to a type. It explains how you can use that type, but it knows <i>nothing</i> about the implementation.<p>I&#x27;m not quite sure what the design goal was with the Widget type, but the closest solution is to replace the member variable in the abstract type with some kind of accessor (and to replace the magic negative font sizes with an Option):<p><pre><code>    trait Widget {
        &#x2F;&#x2F; ADDED: Access whatever underlying font
        &#x2F;&#x2F; size you have stored in this type.
        fn desired_font_size(&amp;self) -&gt; Option&lt;i32&gt;;
        &#x2F;&#x2F; ADDED: Access the theme of this object.
        fn theme(&amp;self) -&gt; &amp;Theme;
        &#x2F;&#x2F; High-level interface to get font size.
        &#x2F;&#x2F; (With a default implementation in terms of
        &#x2F;&#x2F; other functions on this trait.)
        fn font_size(&amp;self) -&gt; i32 {
            if let Some(sz) = self.desired_font_size() {
                sz
            } else {
                self.theme().get_standard_font_size()
            }
        }
    }
</code></pre>
I&#x27;m not sure this is how I&#x27;d personally design this, but it should compile.<p>&gt; What IS the idiomatic Rust way to do a cyclical directed graph?<p>Unfortunately, the correct idiomatic way is that you try very hard to avoid doing so. Rust is all about clear ownership, and it doesn&#x27;t like circular references.<p>The usual solution is to put the cyclic graph code into a library, and to use pointers and about 20 lines of <i>unsafe</i> code. (EDIT: See below for a better solution.) It&#x27;s not much different from the C++ solution.<p>The Servo team really wants GCed, safe pointer support in Rust, and design work is well underway. But it&#x27;s going to take a while to stabilize.<p>GUI libraries are an interesting special case: They involve huge class hierarchies, lots of implementation inheritance, circular references, and tricky ownership. Most older OO languages were optimized for this case. Newer languages tend to favor flatter type hierarchies and far less implementation inheritance. Which means that traditional object-oriented GUI designs may be awkward.