ownership

Cannot infer an appropriate lifetime for a closure that returns a reference

半世苍凉 提交于 2019-11-29 16:59:28
问题 Considering the following code: fn foo<'a, T: 'a>(t: T) -> Box<Fn() -> &'a T + 'a> { Box::new(move || &t) } What I expect: The type T has lifetime 'a . The value t live as long as T . t moves to the closure, so the closure live as long as t The closure returns a reference to t which was moved to the closure. So the reference is valid as long as the closure exists. There is no lifetime problem, the code compiles. What actually happens: The code does not compile: error[E0495]: cannot infer an

How to bind multiple fields of a boxed struct without getting “use moved value” error?

我们两清 提交于 2019-11-29 13:59:38
I'm trying to code a generic recursive data structure. As it turns out, I can't as I'm hitting a wall when I want to access more than one field of an owned struct value. I define a struct that will hold a list: struct ListNode<T> { val: T, tail: List<T> } struct List<T>(Option<Box<ListNode<T>>>); The empty list is represented by List(None) . I want to be able to append to a list: impl<T> List<T> { fn append(self, val: T) -> List<T> { match self { List(None) => List(Some(Box::new(ListNode { val: val, tail: List(None), }))), List(Some(node)) => List(Some(Box::new(ListNode { val: node.val, tail:

Delphi Ownership Confusion

我是研究僧i 提交于 2019-11-29 10:57:34
问题 I always thought that the owner is responsible for destroying visual controls and that I can manually control destruction if I pass nil as the owner. Consider the following example: TMyForm = class (TForm) private FButton : TButton; end; ... FButton := TButton.Create(nil); // no owner!! FButton.Parent := Self; I would expect this button to produce a memory leak but it doesn't and in fact the destructor of TButton is called. Further investigation showed that the TWinControl destructor contains

Convert Vec<String> into a slice of &str in Rust?

ぐ巨炮叔叔 提交于 2019-11-29 01:11:11
Per Steve Klabnik's writeup in the pre-Rust 1.0 documentation on the difference between String and &str , in Rust you should use &str unless you really need to have ownership over a String . Similarly, it's recommended to use references to slices ( &[] ) instead of Vec s unless you really need ownership over the Vec . I have a Vec<String> and I want to write a function that uses this sequence of strings and it doesn't need ownership over the Vec or String instances, should that function take &[&str] ? If so, what's the best way to reference the Vec<String> into &[&str] ? Or, is this coercion

how to find the owner of a file or directory in python

好久不见. 提交于 2019-11-28 21:10:17
I need a function or method in Python to find the owner of a file or directory. The function should be like: >>> find_owner("/home/somedir/somefile") owner3 asveikau I'm not really much of a python guy, but I was able to whip this up: from os import stat from pwd import getpwuid def find_owner(filename): return getpwuid(stat(filename).st_uid).pw_name Kurt You want to use os.stat() : os.stat(path) Perform the equivalent of a stat() system call on the given path. (This function follows symlinks; to stat a symlink use lstat().) The return value is an object whose attributes correspond to the

How to bind multiple fields of a boxed struct without getting “use moved value” error?

纵然是瞬间 提交于 2019-11-28 07:42:09
问题 I'm trying to code a generic recursive data structure. As it turns out, I can't as I'm hitting a wall when I want to access more than one field of an owned struct value. I define a struct that will hold a list: struct ListNode<T> { val: T, tail: List<T> } struct List<T>(Option<Box<ListNode<T>>>); The empty list is represented by List(None) . I want to be able to append to a list: impl<T> List<T> { fn append(self, val: T) -> List<T> { match self { List(None) => List(Some(Box::new(ListNode {

How to keep git from changing file ownership

£可爱£侵袭症+ 提交于 2019-11-28 07:34:24
I have been noticing that when I pull from my github repo on a development server(Red Hat) the ownership of the files change after the pull is completed. The .git file used to be owned by me but then I noticed that it would write files as me and I need it to write files as a different user. So i changed the ownership of the .git directory. I stumbled on to git config core.filemode which was true. I since have set to it false. I have not seen a difference after setting this to false. What should I do to keep my files ownership from changing. This doesn't happen to me locally. If it suffices to

Java: how does a component know its owner

丶灬走出姿态 提交于 2019-11-28 06:06:23
问题 Suppose I have a class A and a class B . public class A { private B b; public A() { this.b = new B(); } public B getB() { return this.b; } } public class B { public String getSome() { return "Get some!"; } } I know I can get B through A, because A has (or owns ) B: new A().getB() . But if I have B, can I get A? 回答1: Sure, just add routine getA() in you class B, and change the line in your constructor to public A() { this.b = new B(this); } This of course assumes your class B has a constructor

Taking ownership of files with 'broken' permissions

拟墨画扇 提交于 2019-11-27 22:26:02
I'm trying to overcome the following situation. Given a directory stored on an NTFS volume, where: The directory owner is set to someone else (a non-privileged user for example) The directory DACL is configured to permit access to a specific group of people that does not include the system or Administrators The DACL on the directory actually grants no one access to either take ownership or change the DACL (or in short, the all administrators have been locked out of the folder) But! The account I am running under has administrative rights (SeBackupPrivilege, SeSecurityPrivilege) The existing

C++ How to retrieve a file permission and ownership via win32 api

两盒软妹~` 提交于 2019-11-27 18:46:49
问题 I've been searching over the internet how to retrieve permissions and ownership of a file using win32 api, and yet I have no answer. I'm new with the win32 api , read some guides from the internet, tried to analyze some code associating with this api and still I'm clueless. Could you guys help me out with some piece of advice or some directions , tips etc. I'm sorry that I can't be more specific than that by adding some code, I don't see any reason to import any code of my own since the only