Skip to content

Commit

Permalink
Added generics to types
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorlott committed Jan 16, 2023
1 parent 97018b0 commit 6efa27d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl ToTokens for TypeStructure {

impl TypeAlias {
pub fn new<'a>(source_code: &'a str, ident: &'a Ident, ty: &'a Type, generics: Option<Generics>) -> Self {
let type_doc = doc_type(ident, ty, source_code);
let type_doc = doc_type(ident, ty, &generics, source_code);

new!({
clone[ident, ty, generics],
Expand Down
2 changes: 1 addition & 1 deletion src/docs/type.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Use `{name}` as a type.
```no_run
type {name} = {ty};
type {name}{generics} = {ty};
{source_code}
```
Expand Down
8 changes: 5 additions & 3 deletions src/tools.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ::rustfmt::{format_input, Input};
use quote::{format_ident, ToTokens};
use quote::{format_ident, ToTokens, quote};
use std::{io::Sink, collections::HashSet};
use syn::{self, parse_quote, Field, Ident, Type, Generics};

Expand Down Expand Up @@ -92,15 +92,17 @@ pub(crate) use new;
pub(crate) use ident;


pub fn doc_type(name: &Ident, ty: &Type, source_code: &str) -> String {
pub fn doc_type(name: &Ident, ty: &Type, generics: &Option<Generics>, source_code: &str) -> String {
let name = name.to_string();
let ty = ty.to_token_stream().to_string().replace(' ', "");
let generics = quote!(#generics).to_string();

format!(
include_str!("docs/type.md"),
source_code = source_code,
name = name,
ty = ty
ty = ty,
generics = generics
)
}
fn doc_field(name: &Ident, ty: &Type, parent: &str) -> String {
Expand Down

0 comments on commit 6efa27d

Please sign in to comment.