MCPcopy Index your code
hub / github.com/RustPython/RustPython / fmt_display

Method fmt_display

crates/compiler-core/src/bytecode.rs:967–1016  ·  view source on GitHub ↗
(&self, f: &mut fmt::Formatter<'_>)

Source from the content-addressed store, hash-verified

965
966impl<C: Constant> BorrowedConstant<'_, C> {
967 pub fn fmt_display(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
968 match self {
969 BorrowedConstant::Integer { value } => write!(f, "{value}"),
970 BorrowedConstant::Float { value } => write!(f, "{value}"),
971 BorrowedConstant::Complex { value } => write!(f, "{value}"),
972 BorrowedConstant::Boolean { value } => {
973 write!(f, "{}", if *value { "True" } else { "False" })
974 }
975 BorrowedConstant::Str { value } => write!(f, "{value:?}"),
976 BorrowedConstant::Bytes { value } => write!(f, r#"b"{}""#, value.escape_ascii()),
977 BorrowedConstant::Code { code } => write!(f, "{code:?}"),
978 BorrowedConstant::Tuple { elements } => {
979 write!(f, "(")?;
980 let mut first = true;
981 for c in *elements {
982 if first {
983 first = false
984 } else {
985 write!(f, ", ")?;
986 }
987 c.borrow_constant().fmt_display(f)?;
988 }
989 write!(f, ")")
990 }
991 BorrowedConstant::Slice { elements } => {
992 write!(f, "slice(")?;
993 elements[0].borrow_constant().fmt_display(f)?;
994 write!(f, ", ")?;
995 elements[1].borrow_constant().fmt_display(f)?;
996 write!(f, ", ")?;
997 elements[2].borrow_constant().fmt_display(f)?;
998 write!(f, ")")
999 }
1000 BorrowedConstant::Frozenset { elements } => {
1001 write!(f, "frozenset({{")?;
1002 let mut first = true;
1003 for c in *elements {
1004 if first {
1005 first = false
1006 } else {
1007 write!(f, ", ")?;
1008 }
1009 c.borrow_constant().fmt_display(f)?;
1010 }
1011 write!(f, "}})")
1012 }
1013 BorrowedConstant::None => write!(f, "None"),
1014 BorrowedConstant::Ellipsis => write!(f, "..."),
1015 }
1016 }
1017
1018 pub fn to_owned(self) -> ConstantData {
1019 use ConstantData::*;

Callers 2

fmtMethod · 0.80
fmt_disMethod · 0.80

Calls 1

borrow_constantMethod · 0.45

Tested by

no test coverage detected