pub trait Printer<'tcx>: Sized {
Show 15 methods
// Required methods
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
fn print_region(&mut self, region: Region<'tcx>) -> Result<(), PrintError>;
fn print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError>;
fn print_dyn_existential(
&mut self,
predicates: &'tcx List<PolyExistentialPredicate<'tcx>>,
) -> Result<(), PrintError>;
fn print_const(&mut self, ct: Const<'tcx>) -> Result<(), PrintError>;
fn print_crate_name(&mut self, cnum: CrateNum) -> Result<(), PrintError>;
fn print_path_with_simple(
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
disambiguated_data: &DisambiguatedDefPathData,
) -> Result<(), PrintError>;
fn print_path_with_impl(
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
self_ty: Ty<'tcx>,
trait_ref: Option<TraitRef<'tcx>>,
) -> Result<(), PrintError>;
fn print_path_with_generic_args(
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
args: &[GenericArg<'tcx>],
) -> Result<(), PrintError>;
fn print_path_with_qualified(
&mut self,
self_ty: Ty<'tcx>,
trait_ref: Option<TraitRef<'tcx>>,
) -> Result<(), PrintError>;
// Provided methods
fn print_def_path(
&mut self,
def_id: DefId,
args: &'tcx [GenericArg<'tcx>],
) -> Result<(), PrintError> { ... }
fn print_impl_path(
&mut self,
impl_def_id: DefId,
args: &'tcx [GenericArg<'tcx>],
) -> Result<(), PrintError> { ... }
fn print_coroutine_with_kind(
&mut self,
def_id: DefId,
parent_args: &'tcx [GenericArg<'tcx>],
kind: Ty<'tcx>,
) -> Result<(), PrintError> { ... }
fn default_print_def_path(
&mut self,
def_id: DefId,
args: &'tcx [GenericArg<'tcx>],
) -> Result<(), PrintError> { ... }
fn default_print_impl_path(
&mut self,
impl_def_id: DefId,
self_ty: Ty<'tcx>,
impl_trait_ref: Option<TraitRef<'tcx>>,
) -> Result<(), PrintError> { ... }
}
Expand description
A trait that “prints” user-facing type system entities: paths, types, lifetimes, constants,
etc. “Printing” here means building up a representation of the entity’s path, usually as a
String
(e.g. “std::io::Read”) or a Vec<Symbol>
(e.g. [sym::std, sym::io, sym::Read]
). The
representation is built up by appending one or more pieces. The specific details included in
the built-up representation depend on the purpose of the printer. The more advanced printers
also rely on the PrettyPrinter
sub-trait.
Required Methods§
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>
Sourcefn print_region(&mut self, region: Region<'tcx>) -> Result<(), PrintError>
fn print_region(&mut self, region: Region<'tcx>) -> Result<(), PrintError>
Appends a representation of a region.
Sourcefn print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError>
fn print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError>
Appends a representation of a type.
Sourcefn print_dyn_existential(
&mut self,
predicates: &'tcx List<PolyExistentialPredicate<'tcx>>,
) -> Result<(), PrintError>
fn print_dyn_existential( &mut self, predicates: &'tcx List<PolyExistentialPredicate<'tcx>>, ) -> Result<(), PrintError>
Appends a representation of a list of PolyExistentialPredicate
s.
Sourcefn print_const(&mut self, ct: Const<'tcx>) -> Result<(), PrintError>
fn print_const(&mut self, ct: Const<'tcx>) -> Result<(), PrintError>
Appends a representation of a const.
Sourcefn print_crate_name(&mut self, cnum: CrateNum) -> Result<(), PrintError>
fn print_crate_name(&mut self, cnum: CrateNum) -> Result<(), PrintError>
Appends a representation of a crate name, e.g. std
, or even ``.
Sourcefn print_path_with_simple(
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
disambiguated_data: &DisambiguatedDefPathData,
) -> Result<(), PrintError>
fn print_path_with_simple( &mut self, print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>, disambiguated_data: &DisambiguatedDefPathData, ) -> Result<(), PrintError>
Appends a representation of a (full or partial) simple path, in two parts. print_prefix
,
when called, appends the representation of the leading segments. The rest of the method
appends the representation of the final segment, the details of which are in
disambiguated_data
.
E.g. std::io
+ Read
-> std::io::Read
.
Sourcefn print_path_with_impl(
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
self_ty: Ty<'tcx>,
trait_ref: Option<TraitRef<'tcx>>,
) -> Result<(), PrintError>
fn print_path_with_impl( &mut self, print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>, self_ty: Ty<'tcx>, trait_ref: Option<TraitRef<'tcx>>, ) -> Result<(), PrintError>
Similar to print_path_with_simple
, but the final segment is an impl
segment.
E.g. slice
+ <impl [T]>
-> slice::<impl [T]>
, which may then be further appended to,
giving a longer path representation such as slice::<impl [T]>::to_vec_in::ConvertVec
.
Sourcefn print_path_with_generic_args(
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
args: &[GenericArg<'tcx>],
) -> Result<(), PrintError>
fn print_path_with_generic_args( &mut self, print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>, args: &[GenericArg<'tcx>], ) -> Result<(), PrintError>
Appends a representation of a path ending in generic args, in two parts. print_prefix
,
when called, appends the leading segments. The rest of the method appends the
representation of the generic args. (Some printers choose to skip appending the generic
args.)
E.g. ImplementsTraitForUsize
+ <usize>
-> ImplementsTraitForUsize<usize>
.
Sourcefn print_path_with_qualified(
&mut self,
self_ty: Ty<'tcx>,
trait_ref: Option<TraitRef<'tcx>>,
) -> Result<(), PrintError>
fn print_path_with_qualified( &mut self, self_ty: Ty<'tcx>, trait_ref: Option<TraitRef<'tcx>>, ) -> Result<(), PrintError>
Appends a representation of a qualified path segment, e.g. <OsString as From<&T>>
.
If trait_ref
is None
, it may fall back to simpler forms, e.g. <Vec<T>>
or just Foo
.
Provided Methods§
Sourcefn print_def_path(
&mut self,
def_id: DefId,
args: &'tcx [GenericArg<'tcx>],
) -> Result<(), PrintError>
fn print_def_path( &mut self, def_id: DefId, args: &'tcx [GenericArg<'tcx>], ) -> Result<(), PrintError>
Appends a representation of an entity with a normal path, e.g. “std::io::Read”.
Sourcefn print_impl_path(
&mut self,
impl_def_id: DefId,
args: &'tcx [GenericArg<'tcx>],
) -> Result<(), PrintError>
fn print_impl_path( &mut self, impl_def_id: DefId, args: &'tcx [GenericArg<'tcx>], ) -> Result<(), PrintError>
Like print_def_path
, but for DefPathData::Impl
.
fn print_coroutine_with_kind( &mut self, def_id: DefId, parent_args: &'tcx [GenericArg<'tcx>], kind: Ty<'tcx>, ) -> Result<(), PrintError>
fn default_print_def_path( &mut self, def_id: DefId, args: &'tcx [GenericArg<'tcx>], ) -> Result<(), PrintError>
fn default_print_impl_path( &mut self, impl_def_id: DefId, self_ty: Ty<'tcx>, impl_trait_ref: Option<TraitRef<'tcx>>, ) -> Result<(), PrintError>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.