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
// The example below gives the following: | |
// | |
// "error: cannot borrow `*self` as mutable more than once at a time" | |
// | |
// I understand why, but I am wondering if it is possible to define | |
// "setter" methods within the trait in a way similar to this? | |
#[deriving(Show)] | |
pub struct MyStruct<'a> { i: int, j: int } |
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
// Is it considered bad practise to do something like this? | |
// Or is it fine? Common even? | |
// | |
// I'm specifically referring to impl'ing a trait method for a | |
// struct that returns a mutable reference to itself? In my | |
// current situation, it seems it will save a lot of unnecessary | |
// impl'ing when deriving from trait "A". | |
#[deriving(Show)] | |
pub struct MyStruct<'a> { i: int } |
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 |
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
/* | |
I want a 'MyStruct' that can take any of the floating point primitive types. | |
When instantiating a 'MyStruct', I want to do so with MyStruct::new(val), | |
which should create a struct with val: val, but should also initialise | |
a: 0.0(f32/f64 - whatever it's floating point type is) and | |
b: 1.0(f32/f64 - whatever it's floating point type is). | |
Can I do this with a single impl method (like below)? Am I on the right | |
track, or is there a better way to handle this situation in Rust? (I'm | |
coming from c++). |
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
//--------------- main.rs --------------------- | |
extern crate rand; // Why do I have to use this here, when I've already done so in a.rs? | |
mod a; | |
mod b; | |
fn main() { | |
a::test(); | |
b::test(); |
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
mindTree:ofJenAI Mitch$ make | |
Compiling OF library for Release | |
make[2]: Nothing to be done for `ReleaseABI'. | |
Done! | |
Compiling ofJenAI for Release | |
find: demos: No such file or directory | |
find: demos: No such file or directory | |
find: demos: No such file or directory |
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
mindTree:ofJenAI Mitch$ make | |
Compiling OF library for Release | |
make[2]: Nothing to be done for `ReleaseABI'. | |
Done! | |
Compiling ofJenAI for Release | |
find: demos: No such file or directory | |
find: demos: No such file or directory | |
Compiling src/main.cpp |
NewerOlder