Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[macro_export]
- macro_rules! static_ty {
- ($ty: ty) => {
- use std::sync::Once;
- impl $ty {
- fn static_ref(self) -> &'static $ty {
- static mut TY: Option<$ty> = None;
- static INIT: Once = Once::new();
- unsafe {
- INIT.call_once(|| TY = Some(self));
- TY.as_ref().unwrap()
- }
- }
- }
- };
- }
- fn main() {
- println!("Hello, world!");
- let b = B(16);
- let c = b.static_ref();
- println!("{:?}",c);
- bb(*c);
- let a = A;
- let mut set = std::collections::HashSet::with_capacity(1);
- println!("{:?}", set.insert(1));
- std::mem::drop(a);
- println!("{:?}", set.insert(1));
- println!( "{}", format_args!("Hello [{x:6}] h!", x="x1234"));
- println!("Hello {:1$} h!", "x", 5);
- println!("Hello {1:0$} h!", 5, "x");
- println!("Hello {:width$} h!", "x", width = 5);
- println!("{}", format!("0x{:0>width$}",123, width=8));
- println!("{}", format!("{:0>64x}",123));
- println!("{}", format!("{}", u64::from_str_radix(&"0x3eeb35"[1..], 16).unwrap()));
- }
- use std::collections::BTreeMap;
- struct A();
- impl Drop for A {
- fn drop(&mut self) {
- println!("drop A");
- }
- }
- #[derive(Debug, Clone, Default)]
- struct B(usize);
- static_ty!(B);
- fn bb(bb: B) {
- println!("{:?}",bb);
- }
Add Comment
Please, Sign In to add comment