51 questions
3
votes
1
answer
1k
views
What is "0is" notation in Rust?
As seen in this repository:
https://github.com/ReactiveX/RxRust/blob/master/src/lib.rs#L110
let gen = move |:| {
let it = range(0is, 20is);
// ~~~ ~~~~
let q = Box::new(...
3
votes
1
answer
673
views
What is a modern analog to the deprecated std::raw::Repr?
I'm looking through some old (~2014) Rust code and I'm seeing this code block:
fn compile(self, func:&UncompiledFunction<'a>) -> &'a Val {
unsafe {
use std::raw::Repr;
...
3
votes
1
answer
635
views
Unable to build Hyper - invalid character `-` in crate name
I am trying to run the hyper example listed on the Github readme.
extern crate hyper;
use std::io::Write;
use hyper::Server;
use hyper::server::Request;
use hyper::server::Response;
use hyper::net::...
18
votes
2
answers
6k
views
Why does #[derive(Show)] not work anymore?
With today's Rust nightly the following code doesn't compile anymore:
#[derive(Show)]
enum S {
A,
B
}
fn main() {
println!("{}", S::A);
}
Instead it gives me the following error message:
...
9
votes
1
answer
707
views
How to rewrite code to new unboxed closures
Can somebody help me to rewrite this piece of code with new unboxed closures:
struct Builder;
pub fn build(rules: |params: &mut Builder|) -> Builder {
let mut builder = Builder::new();
...
6
votes
2
answers
410
views
How is 999µs too short but 1000µs just right?
When I run the following code, I get some output:
use std::thread::Thread;
static DELAY: i64 = 1000;
fn main() {
Thread::spawn(move || {
println!("some output");
});
std::io::...
2
votes
1
answer
3k
views
How to get square root in Rust 0.13.0?
In 0.13.0-nightly the following code won't compile:
fn main() {
let a = (10.5f64).sqrt();
}
I get the error:
error: type `f64` does not implement any method in scope named `sqrt`
What am I doing ...
3
votes
1
answer
615
views
Rust won't narrow down types? Or did I make a mistake
Trying to write something similar to Haskell's HList, with the ability to search by type. With the below code, in play.rust-lang.org version rustc 0.13.0-dev (567b90ff0 2014-12-13 20:02:15 +0000) I ...
7
votes
3
answers
14k
views
Generating secure random numbers in Rust
I can see I have to import like this:
use std::io::IoResult;
use std::num::{Int, ToPrimitive};
use std::rand::{OsRng, Rng};
Then make a new instance of OsRng, and try to generate a new u32 int from ...
1
vote
1
answer
177
views
Type information of a proc() cannot be inferred if not passed into spawn()
This compiles:
use std::num::pow;
pub fn main() {
let (tx, rx): (Sender<u64>, Receiver<u64>) = channel();
let square_tx = tx.clone();
let square = proc() {
let mut x ...
9
votes
1
answer
6k
views
Declaring array using a constant expression for its size
I have a newtype wrapper around an array. I assumed that I could use size_of instead of manually passing the size of the array around, but the compiler thinks I'm wrong.
use std::mem::{size_of, ...
2
votes
2
answers
2k
views
How would you stream output from a Process in Rust?
This question refers to Rust as of October 2014.
If you are using Rust 1.0 or above, you best look elsewhere for a solution.
I have a long running Rust process that generates log values, which I'm ...
2
votes
2
answers
6k
views
Cargo.toml for lib
I want to create a library for rust. This is the Cargo.toml file for my project :
[package]
name = "binary_tree"
version = "0.0.1"
authors = ["Guillaume Bersac <[email protected]>"]
[lib]
...
5
votes
1
answer
746
views
"borrowed value does not live long enough" when using a struct with a slice
Editor's note: The code in this question predates Rust 1.0. Since then, semantics have changed and some of the assertions made in the question are no longer true.
I have the following piece of code:
...
1
vote
2
answers
5k
views
How do I state that I want a struct which contains a reference to something which implements a trait?
Editor's note: The code presented in the question compiles as-is in Rust 1.0.
I've tried:
trait Inner {}
struct Outer<'a> {
inner: &'a Inner,
}
but the compiler complains:
...