-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't refer to 'this in generic bounds? #50
Comments
Unfortunately, ouroboros does not support this use case. The primary
difficulty is that the generic parameter is used in places that aren't
self-referencing, such as the Heads struct returned by `.into_heads()`.
Theoretically, this might be supportable if ouroboros can detect which
fields generic parameters are used in, but that is a level of complexity I
am not willing to add at the moment.
…On Sat, Nov 27, 2021 at 5:30 PM Torne Wuff ***@***.***> wrote:
use std::io::Read;struct Foo<R: Read>(R);struct Bar<'a, R: Read + 'a>(&'a Foo<R>);
#[ouroboros::self_referencing]struct Test<R: Read + 'this> {
foo: Foo<R>,
#[borrows(foo)]
#[covariant]
bar: Bar<'this, R>,
}
I'm trying to define a selfreferencing structure where the referencing
type needs a lifetime on its generic parameter, but adding 'this doesn't
work - it reports it as an undeclared lifetime.
Am I going about this wrong? Is this possible to support?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#50>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOL2YRLTOLDWHKIKOZQ3ZJ3UOGA2FANCNFSM5I4WXJXA>
.
|
I needed that too to store an iterator. I've made a workaround with a specific type pub(super) type EnumeratedDepsLinsIter<'a> = Filter<
Map<Enumerate<Lines<'a>>, fn((usize, &str)) -> (usize, &str)>,
fn(&(usize, &str)) -> bool
>; and something like this // The closures are coerced to function pointers so that their types could be named.
//
// Quting the reference, "A closure expression produces a closure value with a unique,
// anonymous type that cannot be written out.".
//
// Source: https://doc.rust-lang.org/reference/types/closure.html
//
// The type of the whole iterator is needed so that ouroboros crate could handle the
// field of the type of the iterator.
let trim_lines: fn((usize, &str)) -> (usize, &str) = |(i, line)| (i, line.trim());
let is_trimmed_dep_line: fn(&(usize, &str)) -> bool = |(_i, line)| line.starts_with(":dep"); but it's ugly. |
damn I was looking for this exactly. I needed to store a context and a codegen struct I am making for llvm. since if the context gets dropped it would create an issue for generated modules being invalidated. guess i'll have to look else where. |
For anyone interested, I switched to the |
Hi, is there any updates? Thanks! |
Then is it possible that, when using EDIT: I realize I do not need this in generics bounds. Thanks for the library and it works! |
I'm trying to define a selfreferencing structure where the referencing type needs a lifetime on its generic parameter, but adding
'this
doesn't work - it reports it as an undeclared lifetime.Am I going about this wrong? Is this possible to support?
The text was updated successfully, but these errors were encountered: