[rust-dev] NewType change in 0.9

Steven Fackler sfackler at gmail.com
Sat Jan 11 14:06:37 PST 2014


Something like this should work:

pub fn cell_alive(&self, Row(row): Row, Column(column): Column) -> uint {
  return match self.inner[row][column].value {
   dead  => 0,

   alive => 1
  };
}


Steven Fackler


On Sat, Jan 11, 2014 at 2:03 PM, benjamin adamson <
adamson.benjamin at gmail.com> wrote:

> Hello Rust community!
>
> I've been busying myself over the past few weeks learning the different
> features of rust, and I have been working on an implementation of Conway's
> game of life (while trying to explore different features of rust.
>
> In 0.9, it was changed so that you cannot dereference haskell-like
> "NewTypes" with the * operator. In the 0.9 documentation, it says we can
> use pattern matching to extract the underlying type.
>
> Right here in my 0.8 code I dererenced the row parameter here:
> https://github.com/ShortStomp/ConwayGameOfLife-RUST/blob/master/grid.rs#L42
>
> which is a simple 'NewType', with underlying type uint.
>
> My question is, instead of dereferencing the 'Row' and 'Column' types, how
> can I use pattern matching here, to get the underlying uint to index the
> array with the code I just linked?
>
> Thanks in advance! :)
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140111/1333336b/attachment.html>


More information about the Rust-dev mailing list