writeln!(w, "\t#[allow(unused)] pub(crate) fn is_some(&self) -> bool {{").unwrap();
writeln!(w, "\t\tif let Self::Some(_) = self {{ true }} else {{ false }}").unwrap();
writeln!(w, "\t}}").unwrap();
+ writeln!(w, "\t#[allow(unused)] pub(crate) fn is_none(&self) -> bool {{").unwrap();
+ writeln!(w, "\t\t!self.is_some()").unwrap();
+ writeln!(w, "\t}}").unwrap();
writeln!(w, "\t#[allow(unused)] pub(crate) fn take(mut self) -> {} {{", inner_type).unwrap();
writeln!(w, "\t\tif let Self::Some(v) = self {{ v }} else {{ unreachable!() }}").unwrap();
writeln!(w, "\t}}").unwrap();
}
}
+/// Prints the docs from a given attribute list unless its tagged no export
+pub fn writeln_fn_docs<'a, W: std::io::Write, I>(w: &mut W, attrs: &[syn::Attribute], prefix: &str, types: &mut TypeResolver, generics: Option<&GenericTypes>, args: I, ret: &syn::ReturnType) where I: Iterator<Item = &'a syn::FnArg> {
+ writeln_docs_impl(w, attrs, prefix, Some((types, generics,
+ args.filter_map(|arg| if let syn::FnArg::Typed(ty) = arg {
+ if let syn::Pat::Ident(id) = &*ty.pat {
+ Some((id.ident.to_string(), &*ty.ty))
+ } else { unimplemented!() }
+ } else { None }),
+ if let syn::ReturnType::Type(_, ty) = ret { Some(&**ty) } else { None },
+ None
+ )));
+}
+
/// Prints the docs from a given attribute list unless its tagged no export
pub fn writeln_docs<W: std::io::Write>(w: &mut W, attrs: &[syn::Attribute], prefix: &str) {
+ writeln_docs_impl(w, attrs, prefix, None::<(_, _, std::vec::Drain<'_, (String, &syn::Type)>, _, _)>);
+}
+
+pub fn writeln_arg_docs<'a, W: std::io::Write, I>(w: &mut W, attrs: &[syn::Attribute], prefix: &str, types: &mut TypeResolver, generics: Option<&GenericTypes>, args: I, ret: Option<&syn::Type>) where I: Iterator<Item = (String, &'a syn::Type)> {
+ writeln_docs_impl(w, attrs, prefix, Some((types, generics, args, ret, None)))
+}
+
+pub fn writeln_field_docs<W: std::io::Write>(w: &mut W, attrs: &[syn::Attribute], prefix: &str, types: &mut TypeResolver, generics: Option<&GenericTypes>, field: &syn::Type) {
+ writeln_docs_impl(w, attrs, prefix, Some((types, generics, vec![].drain(..), None, Some(field))))
+}
+
+/// Prints the docs from a given attribute list unless its tagged no export
+fn writeln_docs_impl<'a, W: std::io::Write, I>(w: &mut W, attrs: &[syn::Attribute], prefix: &str, method_args_ret: Option<(&mut TypeResolver, Option<&GenericTypes>, I, Option<&syn::Type>, Option<&syn::Type>)>) where I: Iterator<Item = (String, &'a syn::Type)> {
for attr in attrs.iter() {
let tokens_clone = attr.tokens.clone();
let mut token_iter = tokens_clone.into_iter();
},
}
}
+ if let Some((types, generics, inp, outp, field)) = method_args_ret {
+ let mut nullable_found = false;
+ for (name, inp) in inp {
+ if types.skip_arg(inp, generics) { continue; }
+ if if let syn::Type::Reference(syn::TypeReference { elem, .. }) = inp {
+ if let syn::Type::Path(syn::TypePath { ref path, .. }) = &**elem {
+ types.is_path_transparent_container(path, generics, true)
+ } else { false }
+ } else if let syn::Type::Path(syn::TypePath { ref path, .. }) = inp {
+ types.is_path_transparent_container(path, generics, true)
+ } else { false } {
+ // Note downstream clients match this text exactly so any changes may require
+ // changes in the Java and Swift bindings, at least.
+ if !nullable_found { writeln!(w, "{}///", prefix).unwrap(); }
+ nullable_found = true;
+ writeln!(w, "{}/// Note that {} (or a relevant inner pointer) may be NULL or all-0s to represent None", prefix, name).unwrap();
+ }
+ }
+ if if let Some(syn::Type::Reference(syn::TypeReference { elem, .. })) = outp {
+ if let syn::Type::Path(syn::TypePath { ref path, .. }) = &**elem {
+ types.is_path_transparent_container(path, generics, true)
+ } else { false }
+ } else if let Some(syn::Type::Path(syn::TypePath { ref path, .. })) = outp {
+ types.is_path_transparent_container(path, generics, true)
+ } else { false } {
+ // Note downstream clients match this text exactly so any changes may require
+ // changes in the Java and Swift bindings, at least.
+ if !nullable_found { writeln!(w, "{}///", prefix).unwrap(); }
+ nullable_found = true;
+ writeln!(w, "{}/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None", prefix).unwrap();
+ }
+ if if let Some(syn::Type::Reference(syn::TypeReference { elem, .. })) = field {
+ if let syn::Type::Path(syn::TypePath { ref path, .. }) = &**elem {
+ types.is_path_transparent_container(path, generics, true)
+ } else { false }
+ } else if let Some(syn::Type::Path(syn::TypePath { ref path, .. })) = field {
+ types.is_path_transparent_container(path, generics, true)
+ } else { false } {
+ // Note downstream clients match this text exactly so any changes may require
+ // changes in the Java and Swift bindings, at least.
+ if !nullable_found { writeln!(w, "{}///", prefix).unwrap(); }
+ writeln!(w, "{}/// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None", prefix).unwrap();
+ }
+ }
+
}
/// Print the parameters in a method declaration, starting after the open parenthesis, through and
write!(w, "ret").unwrap();
} else if !to_c && self_segs_iter.is_some() && self_segs_iter.unwrap().next().is_none() {
// If we're returning "Self" (and not "Self::X"), just do it manually
- write!(w, "{} {{ inner: Box::into_raw(Box::new(ret)), is_owned: true }}", this_type).unwrap();
+ write!(w, "{} {{ inner: ObjOps::heap_alloc(ret), is_owned: true }}", this_type).unwrap();
} else if to_c {
let new_var = types.write_from_c_conversion_new_var(w, &format_ident!("ret"), rtype, generics);
if new_var {