GithubHelp home page GithubHelp logo

hetaosama / rust-boilerplate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from willbeebe/rust-boilerplate

0.0 0.0 0.0 582 KB

Boilerplate for MacOS and Linux.

License: MIT License

Rust 100.00%

rust-boilerplate's Introduction

Rust Boilerplate

MacOS boilerplate for Rust.

Adjustment to work properly on GNU/Linux distros

Globally substitute the ascii code '127' with the macro 'KEY_BACKSPACE'.

Macros

compr!

A list comprehension macro.

vec_of_strings!

A vector initialisation macro.

Terminal helpers

input(prompt: &str) -> String

Prompts the user for input and returns it as a string.

cls()

Clears the terminal window on some terminal emulators.

e.g. does not work with the Intellij terminal.

type_of<T>(_: &T) -> String

Returns the type of variable T.

unix_shell(x: &str)

Executes slices as unix shell commands.

  • Some shell commands will not work on all terminal emulators. (e.g. "clear" in the Intellij terminal).

  • Compound shell commands will not work properly (e.g. commands using the "&&" operator).

Random numbers

seed()

Seeds the pseudo-random number generator with unix time.

pseudo(x: i32, y: i32) -> i32

Generates a pseudo-random number between x and y.

Strings and chars

remove_empty_strings(v: Vec<String>) -> Vec<String>

Removes all empty strings from a vector of strings.

nth_char(x: &str, n: usize) -> char

Returns the nth char (zero indexed) from a slice.

is_digits(x: &str) -> bool

Checks if a slice consists only of digits.

is_i32(x: &str) -> bool

Checks if a slice represents an i32 integer.

is_f64(x: &str) -> bool

Checks if a slice represents an f64 float.

is_number(x: &str) -> bool 

Like the "is_f64" function, but with additional format restrictions.

to_i32(x: &str) -> i32

Converts a slice to an i32 integer.

to_f64(x: &str) -> f64

Converts a slice to an f64 float.

char_count(x: &str) -> usize

Counts the number of chars in a slice.

slice_count(x: &str, y: char) -> usize

Counts the number of substrings in a slice, as delimited by a given char.

word_count(x: &str) -> usize

Counts the number of words in a slice.

line_count(x: &str) -> usize

Counts the number of lines in a slice.

nth_slice(x: &str, y: usize, z: char) -> String

Returns the nth slice (zero indexed) from a larger slice, as delimited by a given char.

nth_word(x: &str, y: usize) -> String

Returns the nth word (zero indexed) from a slice.

nth_line(x: &str, y: usize) -> String

Returns the nth line (zero indexed) from a slice.

File IO

write_to_file(path: &str, data: &str)

Writes data to a file.

file_exists(path: &str) -> bool

Returns true if the file path exists.

append_to_file(path: &str, data: &str)

Appends data to a file.

delete_file(path: &str)

Deletes the file on the named path.

read_from_file(path: &str) -> String

Reads data from a file into a string.

Virtual terminal

  • These functions will not work on Windows.

  • Only ASCII characters will be displayed correctly in the virtual terminal.

  • These functions will not work properly on some terminal emulators (e.g. the IntelliJ terminal).

vt_open()

Opens the virtual terminal.

vt_close(x: &str)

Displays a message, then closes the virtual terminal on the next user key press.

vt_cursor_off()

Hides the virtual cursor.

vt_cursor_on()

Displays the virtual cursor.

vt_rows() -> i32

Returns the number of rows in the virtual terminal.

vt_columns() -> i32

Returns the number of columns in the virtual terminal.

vt_cls()

Clears the virtual terminal.

vt_key_i32() -> i32

Obtains an i32 integer from a virtual terminal key press.

vt_input(x: i32) -> String

Obtains user input as a string with no more than x chars.

vt_put_slice(x: &str)

Displays a slice in the virtual terminal.

vt_render_menu(menu: &mut [String], size: usize, count: usize)

A helper function called by vt_menu.

vt_menu(menu:&mut Vec<String>) -> usize

Returns a usize integer based on the user's selection from a menu.

vt_render_prompt(prompt:&str, buffer:&mut String, pos:usize)

A helper function called by vt_edit_prompt.

vt_edit_prompt(prompt:&str, buffer:&mut String, max:usize) -> String

Displays a prompt to the user with an existing buffer, which can be edited to return a new buffer.

rust-boilerplate's People

Contributors

sammi-turner avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.