Function core_extensions::phantom::as_phantom
source · [−]pub const fn as_phantom<T: ?Sized>(_: &T) -> PhantomData<T>
Available on crate feature
phantom
only.Expand description
Gets the PhantomData
of the passed in type.
Example
use core_extensions::as_phantom;
use std::marker::PhantomData;
fn get_default<T: Default>(_type: PhantomData<T>) -> T {
Default::default()
}
let string = String::new();
let vector = vec![0u8];
assert_eq!(get_default(as_phantom(&string)), "".to_string());
assert_eq!(get_default(as_phantom(&vector)), vec![]);