Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

RustyYato/ptr-to-field

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pointer to Field

Note: This library is no long being worked on, please use generic-field-projection instead.

This workspace is a proof of concept for the pointer to field concept discussed in this Rust Internals discussion.

This workspace does not intend to be a fully fledged implementation, and will likely be missing many key features to making the pointer to field idea truly work.

Basic sketch of how this workspace workspace

#[repr(C)]           // This is required to have a stable layout so that we can create the correct field offsets
#[derive(Project)]   // This derive is given in the ptr-to-field-macro crate
struct Foo {
    pub names: String,
    bar: Bar,
}

It will give the following implementations

pub mod Foo_fields {
    use super::*;

    pub enum names {}

    unsafe impl ptr_to_field_core::Field for names {
        type Parent = Foo;
        type Type = String;

        const META: ptr_to_field_core::FieldMeta = unsafe {
            ptr_to_field_core::FieldMeta::new_unchecked(
                0
            )
        };
    }

    pub(super) enum bar {}

    unsafe impl ptr_to_field_core::Field for names {
        type Parent = Foo;
        type Type = Bar;

        const META: ptr_to_field_core::FieldMeta = unsafe {
            ptr_to_field_core::FieldMeta::new_unchecked(
                std::mem::size_of::<String>()
            )
        };
    }
}

Contributing

See CONTRIBUTING.md

Releases

No releases published

Packages

No packages published

Languages