On Thu, Apr 18, 2013 at 3:34 PM, Graydon Hoare <[email protected]> wrote:

> (Moreover, I think the proposed form of "protected" would not really buy
> much protection anyway, since you could always make up a trait and
> implement it if you wanted access to such a field.)
>

This is the approach that I agree with, as well. If there is a "protected"
API, it is often better off being a trait that is only used by trait
implementers.

For example, a LinkedList<T> might implement:

trait QueueInternal<T> {
    fn head<'r>(&'r self) -> Option<&'r DoublyLinkedNode<T>>;
    fn tail<'r>(&'r self) -> Option<&'r DoublyLinkedNode<T>>;
}

trait DoublyLinkedNode<T> {
    fn next<'r>(&'r self) -> Option<&'r DoublyLinkedNode<T>>;
    fn prev<'r>(&'r self) -> Option<&'r DoublyLinkedNode<T>>;
    fn data(&self) -> T;
}
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to