Hi everyone,
I want to help clean up the Rust codebase and one thing I stumbled
across a few times in the last weeks is the 'spanned' generic struct
from libsyntax::codemap:
pub struct spanned<T> { node: T, span: span }
It is used quite often to conveniently add a span field to types in
libsyntax::ast following a common pattern:
pub type crate = spanned<crate_>;
#[deriving(Eq, Encodable, Decodable)]
pub struct crate_ {
module: _mod,
attrs: ~[attribute],
config: crate_cfg,
}
This may be convenient for the creator of these types---for the user,
however, it often adds a bit of cumbersome indirection because the
fields of the type have to be accessed like this: "crate.node.attrs"
when it would be more intuitive to just write "crate.attrs". One can
work around this of course, but especially for newcomers this setup can
be a little confusing.
So, I thought it might be a good idea if I tried to remove the
spanned<T> struct altogether and added the span field directly to the
types that are wrapped at the moment. If needed, I would also add a
Spanned trait that allows to abstract over anything having a span.
Because this would affect quite a bit of the codebase (albeit not
semantically) I thought, I'd better ask beforehand if you people think
this is a good idea. Or maybe I am missing a reason for keeping the
spanned<T> struct around?
Thanks for reading,
Michael
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev