Rust is a language designed for writing highly reliable and fast software in a simple way. It can be used from high-level code down to hardware-specific code, and from big irons to tiny devices.

learn more…| top users | synonyms

-2
votes
0answers
9 views

Rust seems to allocate the same space in memory for an array of booleans as an array of 8 bit integers

Running this code in rust:fn main() {println!("{:?}", std::mem::size_of::<[u8; 1024]>());println!("{:?}", std::mem::size_of::<[bool; 1024]>());}1024 1024This is ...
-2
votes
1answer
38 views

Is this Rust code that uses the Windows API “safe”?

use winapi::um::processthreadsapi::OpenProcess;use winapi::shared::minwindef::{DWORD, FALSE};use winapi::shared::ntdef::NULL;use winapi::um::winnt::{HANDLE, PROCESS_ALL_ACCESS};use winapi::um::...
1
vote
0answers
27 views

How can I make the proxy type just for implementing some trait for it?

I want to implement some foreign traits (ToSql and FromSql from diesel crate) for the foreign types (chrono::Duration from chrono crate). I did this:pub struct ChronoDurationProxy(pub chrono::...
2
votes
0answers
75 views

Borrow checker yoga: Wrapping std::vec::Vec inside own type and exposing iter_mut [duplicate]

To implement a two dimensional vector type, I tried to wrap std::vec::Vec inside my own struct and "reexpose" the vectors iter_mut. This does not work:struct WrappedVector<T> {vector: std:...
4
votes
1answer
45 views

Use Option::map to Box::new a trait object does not work

trait FooTrait {}struct FooStruct;impl FooTrait for FooStruct {}fn main() {let maybe_struct: Option<FooStruct>=None;// Does not compile, "expected trait FooTrait, found struct `...
-1
votes
1answer
38 views

“log” and “simplelog” has begun throwing an exception

I'm using log and simplelog libraries. Previously this code worked:use simplelog::*;CombinedLogger::init(vec![TermLogger::new(LevelFilter::Warn, Config::default()).unwrap(),...
-1
votes
1answer
36 views

cannot infer an appropriate lifetime due to conflicting requirements

I'm fear about lifetime question. I searched and got so many relative results. I feel so different between of them, and I think it is difficult to get the spirit from them. so I decide to ask.The ...
0
votes
0answers
28 views

I can't find a way to convert a u8 slice to str [duplicate]

I want to get a str from &[u8]. This is a simple problem, but I can't find the way.fn main() {let slice=b"hello";let hello: &str=slice.xxx; // what should replace xxx or other ...
1
vote
1answer
46 views

Simplifying Rust macro rules for nested looping

I have a simple macro with three very similar rules:macro_rules! c {($exp:expr, for $i:ident in $iter:expr)=> ({let mut r=vec![];for $i in $iter {r.push($...
6
votes
0answers
54 views

How to overload an operator for a generic right-hand operand? [duplicate]

I have a generic type, Vec2<T>, for which I would like to implement the following operation:Vec2<T>=T * Vec2<T>I have tried this:impl<T: Copy + Mul<Output=T>> ...
1
vote
1answer
49 views

How do you read data from a socket into an offset of an existing buffer?

As per my understanding of TCP, if I send X bytes to a socket, it is pretty much guaranteed that it will get there, although it is possible that the payload may split and arrive in two separate parts (...
1
vote
1answer
49 views

How can I iterate over a 2D vector in functional style?

The following doesn't work, unfortunately:let vecs: Vec<Vec<i32>>=get_vectors();let result=vecs.iter().iter().do_something().do_something_else() // etc...
0
votes
2answers
38 views

How to pass a Arc with a trait as a reference?

How can I pass a reference to Arc<A> so that the following code compiles successfully?use std::sync::Arc;trait A {fn send(&self);}struct B;impl A for B {fn send(&self) {...
0
votes
0answers
16 views

“borrowed value does not live long enough” with a chained method call [duplicate]

I'm learning Rust and confused by borrow checker.struct Clock {hours: i16,minutes: i16,}impl Clock {pub fn new(hours: i16, minutes: i16) -> Clock {Clock {...
2
votes
0answers
59 views

Rust lifetime in closure environment

I want to implement a graph structure in Rust. For this goal, I wrote simple abstractions:pub struct Graph<'a> {pub nodes: Vec<Node>,pub edges: Vec<Edge<'a>>,}#[...

153050per page
angop.ao, elkhabar.com, noa.al, afghanpaper.com, bbc.com, time.com, cdc.gov, nih.gov, xnxx.com, github.com,