mirror of
https://git.proxmox.com/git/rustc
synced 2025-08-16 21:47:04 +00:00
111 lines
2.4 KiB
Rust
111 lines
2.4 KiB
Rust
mod gen;
|
|
|
|
use proc_macro2::{Ident, Literal, TokenStream};
|
|
use ref_cast::RefCast;
|
|
use std::fmt::{self, Debug};
|
|
use std::ops::Deref;
|
|
use syn::punctuated::Punctuated;
|
|
|
|
#[derive(RefCast)]
|
|
#[repr(transparent)]
|
|
pub struct Lite<T: ?Sized> {
|
|
value: T,
|
|
}
|
|
|
|
#[allow(non_snake_case)]
|
|
pub fn Lite<T: ?Sized>(value: &T) -> &Lite<T> {
|
|
Lite::ref_cast(value)
|
|
}
|
|
|
|
impl<T: ?Sized> Deref for Lite<T> {
|
|
type Target = T;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.value
|
|
}
|
|
}
|
|
|
|
impl Debug for Lite<bool> {
|
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(formatter, "{}", self.value)
|
|
}
|
|
}
|
|
|
|
impl Debug for Lite<u32> {
|
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(formatter, "{}", self.value)
|
|
}
|
|
}
|
|
|
|
impl Debug for Lite<usize> {
|
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(formatter, "{}", self.value)
|
|
}
|
|
}
|
|
|
|
impl Debug for Lite<String> {
|
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(formatter, "{:?}", self.value)
|
|
}
|
|
}
|
|
|
|
impl Debug for Lite<Ident> {
|
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(formatter, "{:?}", self.value.to_string())
|
|
}
|
|
}
|
|
|
|
impl Debug for Lite<Literal> {
|
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(formatter, "{}", self.value)
|
|
}
|
|
}
|
|
|
|
impl Debug for Lite<TokenStream> {
|
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(formatter, "`{}`", self.value)
|
|
}
|
|
}
|
|
|
|
impl<'a, T> Debug for Lite<&'a T>
|
|
where
|
|
Lite<T>: Debug,
|
|
{
|
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
Debug::fmt(Lite(&*self.value), formatter)
|
|
}
|
|
}
|
|
|
|
impl<T> Debug for Lite<Box<T>>
|
|
where
|
|
Lite<T>: Debug,
|
|
{
|
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
Debug::fmt(Lite(&*self.value), formatter)
|
|
}
|
|
}
|
|
|
|
impl<T> Debug for Lite<Vec<T>>
|
|
where
|
|
Lite<T>: Debug,
|
|
{
|
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
formatter
|
|
.debug_list()
|
|
.entries(self.value.iter().map(Lite))
|
|
.finish()
|
|
}
|
|
}
|
|
|
|
impl<T, P> Debug for Lite<Punctuated<T, P>>
|
|
where
|
|
Lite<T>: Debug,
|
|
{
|
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
formatter
|
|
.debug_list()
|
|
.entries(self.value.iter().map(Lite))
|
|
.finish()
|
|
}
|
|
}
|