Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I just want to play with DEADBEEF like this:
println!("0x{:X}", "0xDEADBEEF");
And I got this:
the trait bound str: std::fmt::UpperHex is not satisfied
the trait std::fmt::UpperHex is not implemented for str
What I do wrong, why I am not able to print the value?
Just do not wrap the value into a str, and use a proper type marker, u32 would do:
fn main() {
println!("0x{:X}", 0xDEADBEEFu32);
}
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 months ago.
Improve this question
I am trying to run a simple hello world program on the Rust Playground:
fn main() {
println!("hello");
}
But all I get is an error:
Response was not JSON: SyntaxError: The string did not match the expected pattern.
What is going on?
This appears to be the symptomatic message displayed if the server-side of the Rust Playground is unresponsive, likely due to either updates or overloaded usage. There isn't much you can do beyond waiting for it to become responsive.
There is a mirror site here (by the playground's primary developer).
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 10 months ago.
Improve this question
See the code:
struct A {}
impl A {
fn a(&self) {}
}
pub fn main() {
let a = A {};
a.a();
A::a(&a);
}
Why a.a() doesn't need the & while A::a(&a) needs? What's the difference?
In Rust, a.a() is syntax sugar for A::a(&a), so a does get borrowed in both calls. The dot operator does a lot more as well, you can read about that here.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I tried this but it doesn't work.
let result: u8 = opcode & 0xff;
the thing is opcode & 0xff will always return something in 0 -> 255 which would always fit in the u8 but the compiler raise the error expected u8 but found u16. Why did Rust raise the error?
Rust doesn't cast between types implicitly, you have to be explicit about the cast using the as keyword:
let result = opcode as u8;
Note that you can omit the AND operator, the as keyword will automatically truncate the number when converting from a larger type.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
In rust I have the following
use std::io;
fn lookup(host: &str, timeout_duration: time::Duration) -> io::IOResult<Vec<ip::IpAddr>>{
// Some blah implementation here...
}
However I'm getting a compilation error.
src/hello.rs:7:60: 7:89 error: use of undeclared type name `io::IOResult`
I'm confused because there is clearly an IOResult struct in the std::io namespace (as of November 16 2014): http://doc.rust-lang.org/std/io/type.IoResult.html
What am I doing wrong?
Don't capitalize the name (doh): IOResult -> IoResult
The signature is
type IoResult<T> = Result<T, IoError>;
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Here is my program
function say(word) {
console.log(word);
}
function execute(someFunction, value) {
someFunction(value);
}
execute(say, "Hello");
How the value is getting printed through someFunction(value);
Probably, you meant execute to be like this:
function execute(someFunction, value) {
someFunction(value);
}
As it is, your code just calls execute recursively, forever. (Well, until the stack overflows.)
word is not reserved.