Open myl7 opened 4 years ago
This is pretty much what I wanted to do. Thanks for showing me the way -- I was going to ask about it and then caught the flue and was "out for the count." :)
So, looking at your code, and I'm wondering how I'd use this in a static? I'd like to adapt this to my own kernel, but I need to hold it in a static:
static ref FRAME_ALLOCATOR: Mutex<Option<GlobalFrameAllocator<impl Iterator<Item = UnusedPhysFrame>>>> = Mutex::new(None); // Raises E0562
How would I go about making this work?
As Rust currently does not support to use impl Trait
in places other than return value, in these places we should use generic type to avoid the problem.
But in lazy_static block I can not see an easy way to use generic type, so maybe we can only expect Rust to support broader impl Trait
.
Or maybe we can declare the explicit type of FRAME_ALLOCATOR
. But as we used closure to build the allocator, we can never give the type of anonymous struct used for closure, and the generation will be performed all before, other than lazy.
Do I have to wait for this? Or is there some other workaround? I'm not on any kind of schedule, so I don't mind.
On 3/8/20, myl7 notifications@github.com wrote:
As Rust currently does not support to use
impl Trait
in places other than return value, in these places we should use generic type to avoid the problem. But in lazy_static block I can not see an easy way to use generic type, so maybe we can only expect Rust to support broaderimpl Trait
.-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/phil-opp/blog_os/issues/736#issuecomment-596271781
-- Signed, Ethin D. Probst
So far I have not found a solution to this (static varible typed by impl Trait). If I find it, I will post it here as fast as possible.
Maybe we can just simulate the lazy generation? Store the context required by frame generation and generate the frame one by one in method calls, other than using map
in usable_frames_inner
method? I am not sure this will work. I will try it in next few days.
As mentioned in the post:
I suggest to use generic type for
usable_frames
and use an unassociated fn to return the inited BootInfoFrameAllocator. So thatimpl Iterator<Item = UnusedPhysFrame>
will be in the fn return type and it works.Example:
A full example can be found at my repo following the tutorial: https://github.com/myl7/rsos/commit/ec844a86173c48dbbf66a5f52d528280cdaea549