Skip to content

Instantly share code, notes, and snippets.

@mitchmindtree
Last active August 29, 2015 14:02
Show Gist options
  • Save mitchmindtree/843a89ae37d478c3b5c1 to your computer and use it in GitHub Desktop.
Save mitchmindtree/843a89ae37d478c3b5c1 to your computer and use it in GitHub Desktop.
A mismatched types error in Rust
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.
*/
@mitchmindtree
Copy link
Author

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,

impl<'r> Clone for JTimePack<'r> {
    fn clone(&self) -> JTimePack<'r> {
        *self
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment