Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(pin)]
- #![feature(optin_builtin_traits)]
- use std::pin::Pin;
- use std::marker::{Unpin};
- use std::ptr::NonNull;
- struct Unmovable {
- data: String,
- slice: NonNull<String>,
- }
- impl !Unpin for Unmovable {
- }
- impl Unmovable {
- fn new(data: String) -> Self {
- Unmovable {
- data,
- slice: NonNull::dangling(),
- }
- }
- }
- #[cfg(test)]
- mod tests {
- use std::ptr::NonNull;
- use super::Unmovable;
- #[test]
- fn it_works() {
- assert_eq!(2 + 2, 4);
- }
- #[test]
- fn unmovable() {
- let unmoved = Unmovable::new("hello".to_string());
- let mut still_unmoved = unmoved;
- assert_eq!(still_unmoved.slice, NonNull::from(&still_unmoved.data));
- }
- }
Add Comment
Please, Sign In to add comment