Last active
August 29, 2015 14:02
-
-
Save mitchmindtree/843a89ae37d478c3b5c1 to your computer and use it in GitHub Desktop.
A mismatched types error in Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use tempo::Tempo; | |
use time_signature::TimeSignature; | |
#[deriving(Clone)] // The error disappears if I remove this line. | |
#[deriving(Show)] | |
pub struct JTimePack<'r> { | |
sample_rate: int, | |
tempo: &'r Tempo, | |
time_sig: &'r TimeSignature, // << Error is found here pointing to 't' in 'time_sig' | |
ppqn: int | |
} | |
/* | |
The above gives me the following error, | |
error: mismatched types: expected '&time_signature::TimeSignature' but found 'time_signature::TimeSignature' (expected &-ptr but found struct time_signature::TimeSignature) | |
NOTE: I've noticed that TimeSignature derives from Clone already, however Tempo does not. Does this have something to do with it? | |
NOTE2: When a 'JTimePack' is cloned, I intend for the references to be copied so that both resulting 'JTimePack's point to and read from the same Tempo and TimeSignature instances. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It turns out that (at this stage of the pre-nightly Rust build) "#[deriving(Clone)]" causes a de-reference during cloning (hense it found an actual TimeSignature object rather than the reference). I was informed that this would be fixed in the near future, however for now all I had to do was explicitly implement the Clone trait for my JTimePack object,