(&self, ty: TypeId)
| 2001 | } |
| 2002 | |
| 2003 | fn modes_of(&self, ty: TypeId) -> Vec<(String, TypeMode)> { |
| 2004 | let info = self.info(ty); |
| 2005 | let mut result = Vec::new(); |
| 2006 | if !self.r#gen.opts.generate_unused_types { |
| 2007 | // If this type isn't actually used, no need to generate it. |
| 2008 | if !info.owned && !info.borrowed { |
| 2009 | return result; |
| 2010 | } |
| 2011 | } |
| 2012 | // Generate one mode for when the type is owned and another for when |
| 2013 | // it's borrowed. |
| 2014 | let a = self.type_mode_for_id(ty, TypeOwnershipStyle::Owned, "'a"); |
| 2015 | let b = self.type_mode_for_id(ty, TypeOwnershipStyle::Borrowed, "'a"); |
| 2016 | |
| 2017 | if self.uses_two_names(&info) { |
| 2018 | // If this type uses two names then, well, it uses two names. In |
| 2019 | // this situation both modes are returned. |
| 2020 | assert!(a != b); |
| 2021 | result.push((self.result_name(ty), a)); |
| 2022 | result.push((self.param_name(ty), b)); |
| 2023 | } else if a == b { |
| 2024 | // If the modes are the same then there's only one result. |
| 2025 | result.push((self.result_name(ty), a)); |
| 2026 | } else if info.owned || matches!(self.r#gen.opts.ownership, Ownership::Owning) { |
| 2027 | // If this type is owned or if ownership is preferred then the owned |
| 2028 | // variant is used as a priority. This is where the generator's |
| 2029 | // configuration comes into play. |
| 2030 | result.push((self.result_name(ty), a)); |
| 2031 | } else { |
| 2032 | // And finally, failing all that, the borrowed variant is used. |
| 2033 | assert!(!info.owned); |
| 2034 | result.push((self.param_name(ty), b)); |
| 2035 | } |
| 2036 | result |
| 2037 | } |
| 2038 | |
| 2039 | fn print_typedef_record(&mut self, id: TypeId, record: &Record, docs: &Docs) { |
| 2040 | let info = self.info(id); |
no test coverage detected