(value: &Vec<T>, context: &mut WriteContext)
| 1987 | } |
| 1988 | |
| 1989 | fn write_vec_dynamic<T, C>(value: &Vec<T>, context: &mut WriteContext) -> Result<(), Error> |
| 1990 | where |
| 1991 | T: 'static, |
| 1992 | C: Codec<T>, |
| 1993 | { |
| 1994 | let mut has_null = false; |
| 1995 | let mut is_same_type = true; |
| 1996 | let mut first_type_id: Option<std::any::TypeId> = None; |
| 1997 | for item in value { |
| 1998 | if C::is_none(item) { |
| 1999 | has_null = true; |
| 2000 | } else if C::is_polymorphic() && is_same_type { |
| 2001 | let concrete_id = C::concrete_type_id(item); |
| 2002 | if let Some(first_id) = first_type_id { |
| 2003 | if first_id != concrete_id { |
| 2004 | is_same_type = false; |
| 2005 | } |
| 2006 | } else { |
| 2007 | first_type_id = Some(concrete_id); |
| 2008 | } |
| 2009 | } |
| 2010 | } |
| 2011 | if C::is_polymorphic() && is_same_type && first_type_id.is_none() { |
| 2012 | is_same_type = false; |
| 2013 | } |
| 2014 | let mut header = 0u8; |
| 2015 | if has_null { |
| 2016 | header |= HAS_NULL; |
| 2017 | } |
| 2018 | if !need_to_write_type_for_field(C::static_type_id()) { |
| 2019 | header |= DECL_ELEMENT_TYPE; |
| 2020 | } |
| 2021 | if is_same_type { |
| 2022 | header |= IS_SAME_TYPE; |
| 2023 | } |
| 2024 | if C::is_shared_ref() { |
| 2025 | header |= TRACKING_REF; |
| 2026 | } |
| 2027 | context.writer.write_u8(header); |
| 2028 | if is_same_type && (header & DECL_ELEMENT_TYPE) == 0 { |
| 2029 | if C::is_polymorphic() { |
| 2030 | let type_id = first_type_id.ok_or_else(|| { |
| 2031 | Error::type_error( |
| 2032 | "Unable to determine concrete type for polymorphic collection elements", |
| 2033 | ) |
| 2034 | })?; |
| 2035 | context.write_any_type_info(C::static_type_id() as u32, type_id)?; |
| 2036 | } else { |
| 2037 | C::write_type_info(context)?; |
| 2038 | } |
| 2039 | } |
| 2040 | let elem_ref_mode = if C::is_shared_ref() { |
| 2041 | RefMode::Tracking |
| 2042 | } else if has_null { |
| 2043 | RefMode::NullOnly |
| 2044 | } else { |
| 2045 | RefMode::None |
| 2046 | }; |
nothing calls this directly
no test coverage detected