Singleton Per Call Context (Web Request) in Unity

Neat solution, but each instance of LifetimeManager should use a unique key rather than a constant: private string _key = string.Format(“PerCallContextLifeTimeManager_{0}”, Guid.NewGuid()); Otherwise if you have more than one object registered with PerCallContextLifeTimeManager, they’re sharing the same key to access CallContext, and you won’t get your expected object back. Also worth implementing RemoveValue to ensure … Read more

Rust lifetime error expected concrete lifetime but found bound lifetime

Let’s compare the two definitions. First, the trait method: fn to_c<‘a>(&self, r: &’a Ref) -> Container<‘a>; And the implementation: fn to_c(&self, r: &’a Ref) -> Container<‘a>; See the difference? The latter doesn’t have <‘a>. <‘a> has been specified elsewhere; the fact that it has the same name does not matter: it is a different thing … Read more

Returning iterator of a Vec in a RefCell

You cannot do this because it would allow you to circumvent runtime checks for uniqueness violations. RefCell provides you a way to “defer” mutability exclusiveness checks to runtime, in exchange allowing mutation of the data it holds inside through shared references. This is done using RAII guards: you can obtain a guard object using a … Read more

Extend lifetime of variable

You can’t forcibly extend a value’s lifetime; you just have to return the full Vec. If I may ask, why do you want to return the slice itself? It is almost always unnecessary, since a Vec can be cheaply (both in the sense of easy syntax and low-overhead at runtime) coerced to a slice. Alternatively, … Read more