//! This module contains utilities for rendering turning things into something //! that may be used to render in UI. use super::*; use std::fmt::{self, Display}; use join_to_string::join; /// Contains information about a function signature #[derive(Debug)] pub struct FunctionSignature { /// Optional visibility pub visibility: Option, /// Name of the function pub name: Option, /// Documentation for the function pub doc: Option, /// Generic parameters pub generic_parameters: Vec, /// Parameters of the function pub parameters: Vec, /// Optional return type pub ret_type: Option, /// Where predicates pub where_predicates: Vec, } impl FunctionSignature { pub(crate) fn with_doc_opt(mut self, doc: Option) -> Self { self.doc = doc; self } } impl Display for FunctionSignature { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(t) = &self.visibility { write!(f, "{} ", t)?; } if let Some(name) = &self.name { write!(f, "fn {}", name)?; } if !self.generic_parameters.is_empty() { join(self.generic_parameters.iter()) .separator(", ") .surround_with("<", ">") .to_fmt(f)?; } join(self.parameters.iter()).separator(", ").surround_with("(", ")").to_fmt(f)?; if let Some(t) = &self.ret_type { write!(f, " -> {}", t)?; } if !self.where_predicates.is_empty() { write!(f, "\nwhere ")?; join(self.where_predicates.iter()).separator(",\n ").to_fmt(f)?; } Ok(()) } }