Struct Generator

Source
pub struct Generator { /* private fields */ }
Expand description

A generator to perform zalgo operations.

This is a structure that contains an internal rand::ThreadRng instance.

Implementations§

Source§

impl Generator

Source

pub fn new() -> Self

Creates a new generator with a new ThreadRng instance.

Examples found in repository?
examples/gen.rs (line 7)
6fn main() {
7    let mut generator = Generator::new();
8
9    // Create Zalgo text with Zalgo `char`s in all positions, with a maximum
10    // amount of Zalgo:
11    generator.gen("test", &mut String::new(), &GeneratorArgs::new(true, true, true, ZalgoSize::Maxi));
12
13    // Create Zalgo text with Zalgo `char`s in only the middle and lower
14    // positions, with a minimum amount of Zalgo:
15    generator.gen("test", &mut String::new(), &GeneratorArgs::new(false, true, true, ZalgoSize::Mini));
16
17    // Create Zalgo text with Zalgo `char`s in only the lower position, with a
18    // random amount of Zalgo (can be a low amount or high amount):
19    generator.gen("test", &mut String::new(), &GeneratorArgs::new(false, false, true, ZalgoSize::None));
20
21    // Consequentially, you can also not modify your given text with any Zalgo:
22    // Technically the `ZalgoSize` value given does not matter here.
23    generator.gen("test", &mut String::new(), &GeneratorArgs::new(false, false, false, ZalgoSize::None));
24}
Source

pub fn gen<T: AsRef<str>>( &mut self, text: T, buf: &mut String, args: &GeneratorArgs, )

Generates a String containing Zalgo text. This is customizable via defining whether to include Zalgo text above the given string, in the middle of it, and below it.

The amount of Zalgo text can be (more or less) defined by the value of the size given. Read on the ZalgoSize for more information.

§Examples

Create Zalgo text with Zalgo chars in all positions, with a maximum amount of Zalgo:

use zalgo::{Generator, GeneratorArgs, ZalgoSize};
 
let mut generator = Generator::new();
let args = GeneratorArgs::new(true, true, true, ZalgoSize::Maxi);
let mut out = String::new();
generator.gen("test", &mut out, &args);

Create Zalgo text with Zalgo chars in only the middle and lower positions, with a minimum amount of Zalgo:

use zalgo::{Generator, GeneratorArgs, ZalgoSize};
 
let mut generator = Generator::new();
let args = GeneratorArgs::new(false, true, true, ZalgoSize::Mini);
let mut out = String::new();
generator.gen("test", &mut out, &args);

Create Zalgo text with Zalgo chars in only the lower position, with a random amount of Zalgo (can be a low amount or high amount):

use zalgo::{Generator, GeneratorArgs, ZalgoSize};

let mut generator = Generator::new();
let args = GeneratorArgs::new(false, false, true, ZalgoSize::None);
let mut out = String::new();
generator.gen("test", &mut out, &args);

Consequentially, you can also not modify your given text with any Zalgo:

use zalgo::{Generator, GeneratorArgs, ZalgoSize};

let mut generator = Generator::new();
let args = GeneratorArgs::new(false, false, false, ZalgoSize::None);
let mut out = String::new();
generator.gen("test", &mut out, &args);
// Technically the `ZalgoSize` value given does not matter here.
Examples found in repository?
examples/gen.rs (line 11)
6fn main() {
7    let mut generator = Generator::new();
8
9    // Create Zalgo text with Zalgo `char`s in all positions, with a maximum
10    // amount of Zalgo:
11    generator.gen("test", &mut String::new(), &GeneratorArgs::new(true, true, true, ZalgoSize::Maxi));
12
13    // Create Zalgo text with Zalgo `char`s in only the middle and lower
14    // positions, with a minimum amount of Zalgo:
15    generator.gen("test", &mut String::new(), &GeneratorArgs::new(false, true, true, ZalgoSize::Mini));
16
17    // Create Zalgo text with Zalgo `char`s in only the lower position, with a
18    // random amount of Zalgo (can be a low amount or high amount):
19    generator.gen("test", &mut String::new(), &GeneratorArgs::new(false, false, true, ZalgoSize::None));
20
21    // Consequentially, you can also not modify your given text with any Zalgo:
22    // Technically the `ZalgoSize` value given does not matter here.
23    generator.gen("test", &mut String::new(), &GeneratorArgs::new(false, false, false, ZalgoSize::None));
24}
Source

pub fn gen_simple<T: AsRef<str>>(&mut self, text: T, buf: &mut String)

A simple function to generate a String containing Zalgo text.

Unlike gen, this is not customizable. This produces zalgo above, in the middle, and below the string.

§Examples

Create Zalgo text:

use zalgo::Generator;
 
let mut out = String::new();
 
let mut generator = Generator::new();
generator.gen_simple("test", &mut out);

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.