Welcome to Jonic Developer Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

Recent questions tagged rust

0 votes
439 views
1 answer
    When I create a vector, the length and the capacity are the same. What is the difference between these methods? fn main() { let vec = vec![1, 2, 3, 4, ... "Capacity: {}", vec.capacity()); // Capacity: 5 } See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
229 views
1 answer
    I'm implementing a small utility and the compiler is telling me that a variable (a TcpStream) does not live long enough and is advising me to find a way to ... the problem is solved, but I don't know why. See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
388 views
1 answer
    Is it possible to explain to the compiler that the v variable is good at the line marked as 1 without using unsafe or code that may call panic ... use potentially bad things like unsafe or Option::unwrap See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
339 views
1 answer
    pub type Data = i32; pub struct Foo { data: Data, } impl Foo { pub fn data_mut(&mut self) -> &mut Data { &mut self.data } } pub struct ... and covering with tests). What's the lifetime issue there? See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
232 views
1 answer
    I have this piece of code using futures v0.1: impl ArcService for (Box<MiddleWare<Request>>, Box<ArcService>) { fn call(&self, req: Request, res: ... hyper::Service and using Rust v1.25.0 (nightly) See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
301 views
1 answer
    fn main() { let val = 0; unsafe { foo(&val) } } extern "C" { pub fn foo(val: *const u32); } Implementation in C: void foo(unsigned* ... unchanged even though I'm passing a pointer to the local variable? See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
761 views
1 answer
    I have a 2D array of type f32 (from ndarray::ArrayView2) and I want to find the index of the maximum value in each row, and put the index value into ... that in Rust. What's the fastest way of doing so? See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
514 views
1 answer
    I understand how lifetime parameters apply to functions and structs, but what does it mean for a trait to have a lifetime parameter? Is it a shortcut to ... to its methods, or is it something else? See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
323 views
1 answer
    Is it possible to create a macro which counts the number of expanded items? macro_rules! count { ($($name:ident),*) => { pub enum Count { $( $name = 1 << $i ... expansion index ),* } } } count!(A, B, C); See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
561 views
1 answer
    According to this isuue issue and this answered question it is not possible to simply define a trait alias like: trait Alias = Foo + Bar; The workaround ... define such a macro? How should it look like? See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
205 views
1 answer
    Update: The title of the post has been updated, and the answer has been moved out of the question. The short answer is you can't. Please see my answer to ... stupid? I'm not sure where to go from here. See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
328 views
1 answer
    Sometimes I want to read a single byte from a std::io::Reader. If I try to do this: use std::io::{self, Read}; fn main() { let mut byte: u8 = ... don't know if it's possible or not and would like to know. See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
411 views
1 answer
    I have some non-copyable type and a function that consumes and (maybe) produces it: type Foo = Vec<u8>; fn quux(_: Foo) -> Option<Foo> { Some( ... notbox` notbox }) } Is it possible to work around that? See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
324 views
1 answer
    Is there a way to have a single function that accepts an iterator to either values or references? If not, is there a way to rewrite one or both of the tests so ... 1)); f64::from(sum) / f64::from(len) } See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
277 views
1 answer
    I am trying to make some kind of decoder, that will be able to deserialize entries without actually copying memory, just by mapping values to some ... solution, or I should refactor the code somehow? See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
338 views
1 answer
    I'm trying to update some older code I wrote that basically looks like: trait Foo<T>{} struct Bar<A, B: Foo<A>>{ b: B } This used to work ... way to handle this situation now, or am I missing something? See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
411 views
1 answer
    I have data contained inside a Box, and would like to pattern match on it without accidentally copying the Box's contents from the heap to the stack; how do I ... => {} SomeEnum::AnotherEntry => {} } } See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
544 views
1 answer
    I'm spawning a thread that does some work. Sometimes I want this thread to die after the work is finished, other times I want it to wait for more work to do. To do ... _) => panic!("Oh no!"), } } }); } See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
316 views
1 answer
    This is my code: use std::ptr; struct Query<T>{ data: T, prev: & Query<T>, next: & Query<T>, } impl<T> Query<T>{ fn new(name: T) - ... specifier' where I am referencing &Query<T>. How do I fix this error? See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
288 views
1 answer
    The async/await feature is coming soon, but there are a lot of libraries still using futures 0.1. How do we convert between the two? Convert an async future to 0. ... ; //how can I achieve this ? Ok(()) } See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
453 views
1 answer
    I want a vector for elements that contain a trait such as Eq and I need heterogeneous vectors. For example: let mut x: Vec<Eq> = Vec::new() ... pointers to things I can compare regardless of their types? See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
208 views
1 answer
    I needed to pass a resource between several functions which use a closure as an argument. And within these the data was handled, but it looked for that ... without the use of Mutex, I have some doubts. See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
354 views
1 answer
    Assume the following contrived example: struct Board { squares: Vec<i32>, } struct Point<'a> { board: &'a Board, x: i32, y: i32, } impl ... structs whose lifetimes are tied to the struct creating them? See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
555 views
1 answer
    I'm trying to write code that gets the last element of some vector and do different actions (including mutation of the vector) depending on that element. ... borrowing. Why does my code fails to compile? See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
544 views
1 answer
    To learn Rust, I'm looking at things like the HackerRank 30 days challenge, Project Euler, and other programming contests. My first obstacle is to read ... ; How do I do this idiomatically in Rust? See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
292 views
1 answer
    I'm getting an error[E0275]: overflow evaluating the requirement on this simple code, and I don't know how to resolve it. The error message suggests adding a ... <&Foo<Foo<Foo<...>>>>` for `String` See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
347 views
1 answer
    We have a 'delete all my data' feature. I'd like to delete a set of IPs from many many web log files. Currently at runtime I open a CSV ... have only a single static binary to deploy with no dependencies. See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
0 votes
365 views
1 answer
    The Rust Reference says: The left operand of an assignment or compound-assignment expression is an lvalue context, as is the single operand of a unary ... only doesn't work for (compound-)assignments? See Question&Answers more detail:os...
asked Oct 24, 2021 in Technique[技术] by 深蓝 (71.8m points)
Ask a question:
Welcome to Jonic Developer Community for programmer and developer-Open, Learning and Share
...