Are Handlers intended to be returned? #411
-
I have a question about the intended usage of the Octocrab handlers. I want to create a function for wrapping the pub fn new_issues<'octo>(pat: Option<String>, owner: &str, repo: &str) -> Result<octocrab::issues::IssueHandler<'octo>, ()> {
// instantiate client
let client = match pat {
Some(pat) => octocrab::Octocrab::builder()
.personal_token(pat)
.build()
.unwrap(),
None => octocrab::Octocrab::default(),
};
// initalize and return issues
return Ok(*client.issues(owner, repo))
} Of course since Is there any documentation that I can be directed towards or added to Octocrab about their intended usage to confirm or deny the intention here? If they are not intended to be returned, is there documentation for something similar in Octocrab that can be returned for functionality analogous to the above? (documentation label implied for this issue) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Thank you for your issue! I moved this to discussions, since it is more of a question. Handlers are meant to be short-lived, you're supposed to consume them immediately. I'm not sure what you're trying to do with the Can you provide more detail on what you're trying to achieve? |
Beta Was this translation helpful? Give feedback.
-
Indeed a question, and this is the first repo I have encountered with a "discussions" so I was unfamiliar with it. I am attempting to construct a general If I cannot return it from a wrapped constructor, then I assume that I would need to either reconstruct the same object repeatedly (inefficient), or wrap both the constructor and the other Issue API functions within a general function (awkward usage). Is there some better design pattern here? |
Beta Was this translation helpful? Give feedback.
Well I'm not sure about passing the function as a pointer, but I would probably use closures instead. If you know what the return type will be, you can replace
I
with that type.