Questions tagged [lifetime-scoping]
97 questions
1
vote
1 answer
How to remove a lifetime requirement for an application in pyo3
Here's a reduced form of problem: I have a trait
pub trait GetIter {
type IntoIter: IntoIterator- ;
fn get_iter( &self ) -> Self::IntoIter;
}
There are several use cases where I can implement GetIter on a reference &'a T, but not…

GHPR
- 45
- 6
1
vote
2 answers
Rust lifetimes with async/await
The following code works without an async keyword on the function. After changing it to async what should I do to make it work.
use cgmath::Vector2;
use winit::window::Window;
struct A<'a> {
a: Option<&'a Vector2>,
}
impl A<'_> {
…

Alchemist
- 62
- 5
1
vote
0 answers
Python Lifetimes Package - lifetimes.utils.summary_data_from_transaction_data returns error "AttributeError: 'DataFrame' object has no attribute 'ix"
I am trying to transform the following dataset
This dataset contains about a million rows of customer transaction data. Columns are broken down as follows:
Date - the date of the transaction
Card Number - the unique identifier for each client ( can…

rookiemofo23
- 23
- 3
1
vote
1 answer
Can you specify the lifetime of a moved self parameter?
I have a newtype struct:
pub struct Branch<'repo>(Git2Branch<'repo>);
And I am trying to wrap a method call:
impl <'repo> Branch<'_> {
pub fn into_reference(self) -> Git2Reference<'repo> {
self.0.into_reference()
} …

Tim Keating
- 6,443
- 4
- 47
- 53
1
vote
2 answers
Mutable borrows in loops [Design help]
I am new to Rust having gone through only the Rust book, working on a project which requires capturing a screenshot of the primary display. I am using the scrap crate for this.
fn screen_shot_and_save_image(iter:i32) {
let one_second =…

samarthc_rust
- 13
- 3
1
vote
1 answer
How to move the lifetime of references outside a scope in Rust
Actually I try to implement the following functionality in Rust.
I want to have a structure Node which has a vector to some other Node structures. In addition I have a master vector which keeps all the Node structures which have been…

Horowitzathome
- 359
- 3
- 13
1
vote
0 answers
Can't find the correct lifetime parameter to store loaded fonts
So I'm building a game engine in rust, but I have an issue with finding the correct lifetime parameters/syntax for storing the font data the sdl2 library needs for rendering.
This is a simplified version of what I'm currently doing, but it doesn't…

SethSR
- 59
- 4
1
vote
1 answer
Result with lifetime parameter - enum with lifetime parameter applied to default T<'a> and E<'a> parameter (Rust)
I'm attempting to make a Result with a lifetime parameter, as an additional restrain on the T (::Ok(T)) and E (::Err(E)) generic parameters.
// enums A<'a> and B<'a> elided
pub enum Result<'a, T=A<'a>, E=B<'a>> {
Ok(T),
Err(E),
}
unused…

Willem
- 317
- 2
- 11
1
vote
2 answers
Why use the word 'generic' in lifetime parameters?
When we write:
fn foo<'a, 'b>(x: &'a u32, y: &'b u32) -> &'a u32 {
x
}
Why don't we just refer to the 'as and the 'bs as lifetime parameters as opposed to generic lifetime parameters? It's just a syntactical way to communicate to the compiler a…
anon
1
vote
0 answers
How can I avoid giving a static lifetime to something that already has an explicit lifetime?
I'm building a Rust library that exposes the following simple flow to a C++ client application:
Client Application (CA) calls an API to create a FooClient, which amongst other things creates a tokio::Runtime.
CA calls…

ZachChilders
- 415
- 3
- 15
1
vote
1 answer
Application Lifetime and Add Singleton DI service in ASP.NET Core
I am trying to understand the singleton lifetime in the context of DI in ASP.NET Core.
First, from what I can see a Singleton instance will be available "across application lifetime." But what does "application lifetime" mean? If it's a website and…

Dotnet Dev
- 25
- 4
1
vote
1 answer
Why doesn't Rayon require Arc<_>?
On page 465 of Programming Rust you can find the code and explanation (emphasis added by me)
use std::sync::Arc;
fn process_files_in_parallel(filenames: Vec,
glossary: Arc)
-> io::Result<()>
{
…

Evan Carroll
- 78,363
- 46
- 261
- 468
1
vote
2 answers
Autofac: Dispose off object instance and its dependencies with just the resolved instance?
Say I have an instance of an object, resolved by Autofac like this:
ILifetimeScope scope = rootContainer....
var myService = scope.Resolve(myServiceType);
Now all I have with me is myService. Is there any Autofac API which takes in my variable…

nawfal
- 70,104
- 56
- 326
- 368
1
vote
2 answers
Autofac: Needed: End-Of-Lifetime event for instances handled in a AutofacModule
I use C# and Autofac 4.9.4.
I have an Autofac Module which hooks up to the IComponentRegistration.Activated event. It looks for activated instances of certain classes and registers them in some manager class.
This registration should be limited to…

JSpot
- 450
- 4
- 12
1
vote
0 answers
AutoFac - InstancePerLifetimeScope becomes SingleInstance When Component Resolved as Dependency for Singleton
Original:
Summary:
I'm having an issue with Autofac, where objects which are registered as singletons/'SingleInstance', are having their dependencies that are registered as 'InstancePerLifetimeScope' are ending up becoming 'singletons' after the…

Lightbarrier
- 361
- 1
- 4
- 8