Created
January 24, 2020 15:46
-
-
Save rust-play/3e43d1895c50ffdd3ccf2825eaba8344 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::{self, BufRead}; | |
struct Migration<'a> { | |
pub namespace: &'a str, | |
} | |
impl<'a> Migration<'a> { | |
pub fn len(&self) -> usize { | |
self.namespace.chars().count() | |
} | |
} | |
fn create_migration(namespace: &str) -> *mut () { | |
let boxed = Box::new(Migration { namespace }); | |
Box::into_raw(boxed) as *mut _ | |
} | |
fn main() { | |
let stdin = io::stdin(); | |
let namespace = stdin.lock().lines().next().unwrap().unwrap(); | |
let migration = create_migration(&namespace); | |
let unboxed: Migration<'_> = unsafe { *Box::from_raw(migration as _) }; | |
println!("{}", unboxed.len()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment