cg2 0.4.7

Rust code generator.
Documentation
use alloc::string::String;

use crate::{Flexible, FlexibleList, Generator, generator::impl_alias};

pub fn s<X>(x: X) -> String
where
  X: Flexible,
{
  let mut g = Generator::new();
  x.output_into(&mut g);
  g.into_code()
}

pub fn comma_sep<I>(items: I) -> String
where
  I: FlexibleList,
{
  let mut g = Generator::new();
  g.comma_sep(items);
  g.into_code()
}

pub fn comma_sep_trailing<I>(items: I) -> String
where
  I: FlexibleList,
{
  let mut g = Generator::new();
  g.comma_sep_trailing(items);
  g.into_code()
}

pub fn tuple<V>(values: V) -> String
where
  V: FlexibleList,
{
  let mut g = Generator::new();
  g.tuple(values);
  g.into_code()
}

pub fn quoted<E>(expr: E) -> String
where
  E: Flexible,
{
  let mut g = Generator::new();
  g.quoted(expr);
  g.into_code()
}

impl_alias!(
  pub fn [E](expr: E) -> String
  where
    [E: Flexible]
  {
    quoted(expr)
  },
  [string, str]
);

pub fn parenthesized<E>(expr: E) -> String
where
  E: Flexible,
{
  let mut g = Generator::new();
  g.parenthesized(expr);
  g.into_code()
}

impl_alias!(
  pub fn [E](expr: E) -> String
  where
    [E: Flexible]
  {
    parenthesized(expr)
  },
  [bracketed]
);

pub fn braced<E>(expr: E) -> String
where
  E: Flexible,
{
  let mut g = Generator::new();
  g.braced(expr);
  g.into_code()
}

impl_alias!(
  pub fn [E](expr: E) -> String
  where
    [E: Flexible]
  {
    braced(expr)
  },
  [square_braced]
);

pub fn curlied<E>(expr: E) -> String
where
  E: Flexible,
{
  let mut g = Generator::new();
  g.curlied(expr);
  g.into_code()
}

impl_alias!(
  pub fn [E](expr: E) -> String
  where
    [E: Flexible]
  {
    curlied(expr)
  },
  [curly_braced, block]
);

pub fn unsafe_block<E>(expr: E) -> String
where
  E: Flexible,
{
  let mut g = Generator::new();
  g.unsafe_block(expr);
  g.into_code()
}

pub fn if__<Cond, Body>(cond: Cond, body: Body) -> String
where
  Cond: Flexible,
  Body: Flexible,
{
  let mut g = Generator::new();
  g.if__(cond, body);
  g.into_code()
}

pub fn else_if<Cond, Body>(cond: Cond, body: Body) -> String
where
  Cond: Flexible,
  Body: Flexible,
{
  let mut g = Generator::new();
  g.else_if(cond, body);
  g.into_code()
}

pub fn else__<Body>(body: Body) -> String
where
  Body: Flexible,
{
  let mut g = Generator::new();
  g.else__(body);
  g.into_code()
}

pub fn call<Name, Args>(name: Name, args: Args) -> String
where
  Name: Flexible,
  Args: FlexibleList,
{
  let mut g = Generator::new();
  g.call(name, args);
  g.into_code()
}