lifetime

PHP - session_set_cookie_params(), lifetime doesn't work

不想你离开。 提交于 2019-12-07 03:53:25
As first, I know a lot questions are like mine, but I really don't know what I'm doing wrong... As you might've guessed, I've a PHP script involving sessions. Everything works like a charm, except setting the lifetime of my session. I want to keep the session active for two weeks, but instead my (Chrome) browser says it's set to xpire after the browsing session (and it does). My PHP script: session_name('DSWLogin'); // Naming the session session_set_cookie_params(2*7*24*60*60); // Making the cookie live for 2 weeks session_start(); // Starting the session It really doesn't work. Thanks in

Lifetimes and references to objects containing references

ぃ、小莉子 提交于 2019-12-07 01:02:38
问题 Let's say I have a struct with a reference in it, and another struct with a reference to that struct, something like this: struct Image<'a> { pixel_data: &'a mut Vec<u8>, size: (i32, i32), } struct SubImage<'a> { image: &'a mut Image<'a>, offset: (i32, i32), size: (i32, i32), } The structs have nearly identical interfaces, the difference being that SubImage adjusts position parameters based on its offset before forwarding to the corresponding functions of the contained Image reference. I

Rust lifetime error

喜你入骨 提交于 2019-12-06 16:31:08
Can anyone tell what the lifetime error is in the following code? (simplified from my actual code) I've looked it over myself, but I can't figure out what is wrong or how to fix it. The problem comes when I try to add the Cell , but I'm not sure why. use std::cell::Cell; struct Bar<'a> { bar: &'a str, } impl<'a> Bar<'a> { fn new(foo: &'a Foo<'a>) -> Bar<'a> { Bar{bar: foo.raw} } } pub struct Foo<'a> { raw: &'a str, cell: Cell<&'a str>, } impl<'a> Foo<'a> { fn get_bar(&self) -> Bar { Bar::new(&self) } } The compiler error is error[E0495]: cannot infer an appropriate lifetime for lifetime

Unity: pass parameters to custom lifetime constructor, in xml configuration file

烈酒焚心 提交于 2019-12-06 11:14:35
I wrote my CustomLifetimeManager like this: public class CustomLifetimeManager <T> : LifetimeManager { private readonly string _arg; public CustomLifetimeManager(string arg) { _arg = arg; } } Now, it works easy configuring the container programmatically, but how add it in configuration file like the following? <type type="myTime" mapTo="myImpl"> <lifetime type="CustomLifetimeManager"/> </type> You need to add a second class: A TypeConverter. This class is responsible for taking a string and turning it into whatever type you want. Once you implement it, you can then do something like this in

Non-cancelable dialog being dismissed on search button click

蓝咒 提交于 2019-12-06 07:33:00
I'm showing a non-cancelable dialog in my application, but it gets cancelled if the user presses SEARCH button. I've tried to override onSearchRequested and onKeyDown, but it doesn't help. Any suggestion? I also came across this problem and Jamasan's solution did not work for me. I instead added the following code to my custom dialog class (extending Dialog): @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_SEARCH) { return true; } else { return false; } } keyCode and KeyEvent.KEYCODE_SEARCH are both int. The docs for onKeyDown says If you

Lifetime of a thrown object caught by reference

陌路散爱 提交于 2019-12-06 07:13:58
问题 The C++ Standard, paragraph 15.1.4 sais: The memory for the temporary copy of the exception being thrown is allocated in an unspecified way, except as noted in 3.7.3.1. The temporary persists as long as there is a handler being executed for that exception. I'm wondering why this code crashes (I know that it's not best practice): class magicException { private: char* m_message; public: magicException(const char* message) { m_message = new char[strlen(message) + 1]; strcpy(m_message, message);

How do I return a boxed closure from a method that has a reference to the struct?

痞子三分冷 提交于 2019-12-06 06:06:21
问题 I have a structure that contains a value and I want to obtain a function that operates on this value: struct Returner { val: i32, } impl<'a> Returner { fn get(&'a self) -> Box<Fn(i32) -> i32> { Box::new(|x| x + self.val) } } This fails compilation: error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements --> src/main.rs:7:18 | 7 | Box::new(|x| x + self.val) | ^^^^^^^^^^^^^^^^ | note: first, the lifetime cannot outlive the lifetime 'a as defined on the impl at 5:1...

Why does a MutexGuard require a lifetime parameter in structs but not in function return types? [duplicate]

烂漫一生 提交于 2019-12-06 05:42:43
This question already has answers here : Why can the lifetimes not be elided in a struct definition? (2 answers) What is lifetime elision in very simple terms? (1 answer) Closed last year . I'd like to move a MutexGuard around. Returning a MutexGuard from a function works fine without giving a lifetime parameter. But when packing the guard into a struct, the compiler demands a lifetime parameter for the guard. The following code compiles without errors: struct Queue { queue: Mutex<Vec<i32>>, } impl Queue { pub fn get_mutex_guard(&self) -> MutexGuard<Vec<i32>> { self.queue.lock().unwrap() } }

Passing mutable context into callbacks

杀马特。学长 韩版系。学妹 提交于 2019-12-06 03:46:54
I'm trying to build a simple UI in Rust, but partly scriptable in Lua, using rust-lua53, and having problems working out a good way to give Lua components access to the Lua state. This question/example is a little longer than I'd like, sorry! The core of the UI is a Widget trait with methods to call when keys are pressed or when the screen/window should be redrawn. The type parameter C is the context I'll want to pass in (see later). trait Widget<C> { fn handle_key<'c>(&mut self, key: char, context: &'c mut C); } There's a UI struct which handles the event loop, reading keys and calling the

type parameter for function vs struct (lifetime issue)

坚强是说给别人听的谎言 提交于 2019-12-05 22:34:47
Consider the following test case: #![allow(unstable)] trait Choose<'o> { fn choose(a: &'o u64, b: &'o u32) -> Self; } impl<'o> Choose<'o> for &'o u64 { fn choose(a: &'o u64, _b: &'o u32) -> &'o u64 { a } } impl<'o> Choose<'o> for &'o u32 { fn choose(_a: &'o u64, b: &'o u32) -> &'o u32 { b } } // ' struct Handler { a: u64, b: u32, } impl Handler { fn new() -> Handler { Handler { a: 14, b: 15 } } fn find<'a, V, W>(&'a mut self, value: W) -> Option<V> where V: Choose<'a>, W: PartialEq<V> { // ' let v = Choose::choose(&self.a, &self.b); if value == v { Some(v) } else { None } } } fn main() { let