Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [lifetime]

A variable's life-time is the time during which the variable is bound to a specific memory location. The life time starts when the variable is allocated and ends when it is deallocated.

0 votes
1 answer
17 views

Rust generic lifetime elision issue

I am trying to a implement generic observable collections for use with a UI framework I'm writing. I'm currently having an issue with lifetimes not being elidable in generics. For brevity the ...
Jacob Green's user avatar
0 votes
1 answer
42 views

Lifetimes of &mut self inside Rust methods when asigning in an inner scope [duplicate]

The Context I am trying to get wgpu to work with winit. I followed the winit v0.30 docs on how to create a window and am now trying to follow the learn wgpu tutorial that unfortunately uses wini v0.29 ...
Pizza98's user avatar
0 votes
0 answers
16 views

How to dynamically use plotter SegmentValue?

I have a struct Band: pub struct Band{ pub name: String, pub start_dt: NaiveDateTime, pub end_dt: NaiveDateTime, pub stage: String, pub selected: bool, } I'm using the plotters ...
Tare's user avatar
  • 604
-1 votes
0 answers
37 views

Lifetime of Temporary Passed to Multiple Functions by Const Reference in the Same Lexical Expression [duplicate]

According to the answers to this question, a temporary created in an expression lasts for the entire expression. This seems to imply that we can pass a temporary into and return it from functions by ...
user985091's user avatar
2 votes
0 answers
35 views

Invariance of mutable references over their lifetimes [closed]

The Rustonomicon's chapter on subtyping and variance contains the passage Also, we saw that it was not ok for us to treat &mut &'a U as a subtype of &mut &'b U, therefore we can say ...
Alessandro Power's user avatar
0 votes
0 answers
27 views

Rust lifetimes in structs [duplicate]

Why is it not working? struct Test<'s>(&'s mut i32); impl<'n, 's: 'n> Test<'s> { fn new(i: &'s mut i32) -> Self { Self(i) } fn cast(&'s mut self) ...
Danila's user avatar
  • 73
3 votes
1 answer
61 views

Define lifetime for associative type without lifetime bound

I am implementing FromStr for a type and for the error I want to return the passed &str inside a wrapper struct. However, this requires the the struct to have a lifetime bound for the &str but ...
Tobiky's user avatar
  • 63
0 votes
1 answer
47 views

rust [mockall return_once] borrowed value does not live long enough

I am learning Rust and I am writing a unit test using mockall library. I have some String in my test and I want to pass it to multiple mock closures. If I pass it directly, then I understand that I ...
ekimpl's user avatar
  • 501
0 votes
1 answer
62 views

Downcasting a type with a named lifetime parameter

I have the following code: use std::any::Any; use std::borrow::Cow; // Base trait for downcasting pub trait AsTranslationUnit<'a> { fn as_any(&self) -> &dyn Any; } pub trait ...
Alex Vergara's user avatar
  • 2,049
0 votes
1 answer
44 views

Returning and using an reqwest::Response from an async method

I am hoping to improve some logic that crafts and returns a Future for a reqwest::Response by adding in logic to catch, reauthenticate, and retry when the response is a 401. However, even before I get ...
jwimberley's user avatar
  • 1,748
0 votes
1 answer
109 views

How to create a self referential struct?

Context: I'm working on a very fast algorithm to solve the Advent of Code 2023 Day 8 part 2 challenge without the least-common-multiple approach (which is meant to be impossible, hence the ...
NoBullsh1t's user avatar
1 vote
0 answers
70 views

Winking Out with polymorphic memory resources: efficient resource release and objects lifetime

I'm trying to understand "winking out" technique through examples (as I couldn't find, yet, a clean explanation). My goal is to acquire non-UB techniques that can be efficient when releasing ...
Oersted's user avatar
  • 1,706
0 votes
1 answer
54 views

System.ObjectDisposedException: Cannot access a disposed context instance

I have a problem occurring when I execute: await alarmHandler.InitRedis("setting"); System.ObjectDisposedException: Cannot access a disposed context instance. A common cause of this error ...
slim shady's user avatar
0 votes
0 answers
45 views

implementation of trait is not general enough

Let's say I have access to the following functions: trait T<'a> {} impl<'a> T<'a> for &'a str {} fn takes_fn(f: impl Fn(&str)) {} fn take_both<'a, X:T<'a>>(a: &...
lovasoa's user avatar
  • 6,715
1 vote
0 answers
21 views

Understanding lifetime across async [duplicate]

I have this rust program: // src/main.rs #![feature(async_closure)] use std::error::Error; use std::future::Future; struct Foo { data: String, } impl Foo { pub async fn show<J, F>(&...
handle's user avatar
  • 69

15 30 50 per page
1
2 3 4 5
153