GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Fancyflame/Any-ref-rs: Creating a bundle that can carry an owner and a struct borrows it

BranchesTags
Open more actions menu

Latest commit

 

History

25 Commits
25 Commits

Folders and files

NameName
Last commit message
Last commit date
any_ref
any_ref
 
 
any_ref_macro
any_ref_macro
 
 
.gitignore
.gitignore
 
 
Cargo.lock
Cargo.lock
 
 
Cargo.toml
Cargo.toml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

Any-ref-rs

📖 Documentation

documentation

❓ What is any_ref

any_ref is a crate that allows you to capture things that are not 'static with memory safety.

Here's a simple demo to see how it works.

// Create the type `ReturnVec` stands for `Vec<&'_ T>`
make_any_ref! {
    type ReturnVec<T: 'static> = for<'a> Vec<&'a T>;
}

let moved_ar;
{
    // This is the owner
    let num: Box<(u16, u16, u16, u16)> = Box::new((1, 2, 3, 4));

    // Initialize an `AnyRef`
    let ar: AnyRef<ReturnVec<u16>, _> = AnyRef::new(
        num, |x| vec![&x.0, &x.1, &x.2, &x.3]
    );

    // Move out of this scope
    moved_ar = ar;
}

// Read the reference of the value
assert_eq!(moved_ar.get(), &vec![&1, &2, &3, &4]);

📣 Compatibility Notice

Below the version of rustc 1.61, due to a problem with type inferer, we cannot use AnyRef::new to initialize AnyRef in stable rust, using new_any_ref as an temporary alternative solution. Please upgrade your rustc to 1.61.0 or later if possible!

🤔 Troubleshooting

Everyone is welcomed to find out bugs or put forward your ideas of improvement, and please feel free to open an issue if you have any questions.

This crate is maintained (Written in 2022/6/19).

⚖️ License

MIT

❤️ Acknowledgements

Thanks to people in the rust forum who helped me find out serveral problems and bugs, thanks for your effort!

About

Creating a bundle that can carry an owner and a struct borrows it

Topics

rustself-reference

Resources

Readme
MIT license
Activity

Stars

5 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.