MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / print_ty

Method print_ty

crates/rust/src/interface.rs:1789–1855  ·  view source on GitHub ↗
(&mut self, ty: &Type, mode: TypeMode)

Source from the content-addressed store, hash-verified

1787 }
1788
1789 fn print_ty(&mut self, ty: &Type, mode: TypeMode) {
1790 // If we have a typedef of a string, list, or map, the typedef is an
1791 // alias for `String`, `Vec<T>`, or `Map<K, V>`. If this is a borrow,
1792 // instead of borrowing them as `&String` or `&Vec<T>`, use `&str` or
1793 // `&[T]` so that callers don't need to create owned copies. Maps are
1794 // borrowed as `&Map<K, V>`.
1795 if let Type::Id(id) = ty {
1796 let id = dealias(self.resolve, *id);
1797 let typedef = &self.resolve.types[id];
1798 match &typedef.kind {
1799 TypeDefKind::Type(Type::String) => {
1800 if let Some(lt) = mode.lifetime {
1801 self.print_borrowed_str(lt);
1802 return;
1803 }
1804 }
1805 TypeDefKind::List(element) => {
1806 if mode.lifetime.is_some() {
1807 self.print_list(element, mode);
1808 return;
1809 }
1810 }
1811 TypeDefKind::Map(key, value) => {
1812 if mode.lifetime.is_some() {
1813 self.print_map(key, value, mode);
1814 return;
1815 }
1816 }
1817 _ => {}
1818 }
1819 }
1820
1821 match ty {
1822 Type::Id(t) => self.print_tyid(*t, mode),
1823 Type::Bool => self.push_str("bool"),
1824 Type::U8 => self.push_str("u8"),
1825 Type::U16 => self.push_str("u16"),
1826 Type::U32 => self.push_str("u32"),
1827 Type::U64 => self.push_str("u64"),
1828 Type::S8 => self.push_str("i8"),
1829 Type::S16 => self.push_str("i16"),
1830 Type::S32 => self.push_str("i32"),
1831 Type::S64 => self.push_str("i64"),
1832 Type::F32 => self.push_str("f32"),
1833 Type::F64 => self.push_str("f64"),
1834 Type::Char => self.push_str("char"),
1835 Type::String => {
1836 assert_eq!(mode.lists_borrowed, mode.lifetime.is_some());
1837 match mode.lifetime {
1838 Some(lt) => self.print_borrowed_str(lt),
1839 None => {
1840 if self.r#gen.opts.raw_strings {
1841 self.push_vec_name();
1842 self.push_str("::<u8>");
1843 } else {
1844 self.push_string_name();
1845 }
1846 }

Callers 15

print_docs_and_paramsMethod · 0.45
print_result_typeMethod · 0.45
type_nameMethod · 0.45
print_optional_tyMethod · 0.45
print_listMethod · 0.45
print_mapMethod · 0.45
print_typedef_recordMethod · 0.45
print_rust_enumMethod · 0.45
print_typedef_optionMethod · 0.45
print_typedef_aliasMethod · 0.45
type_tupleMethod · 0.45

Calls 9

print_borrowed_strMethod · 0.80
print_listMethod · 0.80
print_mapMethod · 0.80
print_tyidMethod · 0.80
push_vec_nameMethod · 0.80
push_string_nameMethod · 0.80
async_support_pathMethod · 0.80
dealiasFunction · 0.50
push_strMethod · 0.45

Tested by

no test coverage detected