A general-purpose utility library for Rust. Its API was mainly inspired by the Python programming language.
This is just a teaser. The library has many more modules and --in most cases-- the modules contain more functions than shown below.
```rust use jabba_lib::jconsole;
fn main() { let name = jconsole::input("Name: "); let name = name.trim(); println!("Hello {}!", name); } ```
Call an external command.
```rust use jabba_lib::jprocess as jproc;
fn main() { let cmd = "ls -al"; jproc::exec_cmd(cmd); } ```
```rust use jabba_lib::jmath;
fn main() { asserteq!(jmath::ispalindrome(101), true); asserteq!(jmath::isprime(97), true); asserteq!(jmath::getdivisors(28), [1, 2, 4, 7, 14, 28]); asserteq!(jmath::factorial(5), 120); asserteq!(jmath::factorialbigint(33).tostring(), "8683317618811886495518194401280000000"); } ```
```rust use jabba_lib::jstring;
fn main() { let name = "Dave"; let reversed = jstring::str_rev(name); // evaD println!("{} <-> {}", name, reversed);
let name = "anna";
println!("{} is palindrome: {}", name, jstring::is_palindrome(name));
} ```
```rust use jabba_lib::jrandom;
fn main() { let number = jrandom::randrange(1, 10); // 10 is excluded println!("random number from [1, 10): {}", number);
let number = jrandom::randint(1, 100); // 100 is included
println!("random number from [1, 100]: {}", number);
let mut numbers = vec![1, 2, 3, 4, 5];
jrandom::shuffle(&mut numbers);
println!("shuffled: {:?}", numbers); // could be [3, 5, 1, 4, 2]
} ```
Supported platforms: Linux (with X server), Windows.
Under Linux you must have the program xsel
installed.
You can install it with your package manager.
Under Linux, the text is pasted on both clipboards (to "primary" and "clipboard").
```rust use jabba_lib::jclipboard;
fn main() { let text = "hello";
jabba_lib::jclipboard::check(); // verify if your platform is supported
jabba_lib::jclipboard::set_text(text).unwrap();
println!("The text {:?} was pasted on the clipboard", text);
let read = jabba_lib::jclipboard::get_text().unwrap();
println!("Contents of the clipboard: {:?}", read);
assert_eq!(read, text);
} ```
Spell a number (write out in words).
```rust use jabba_lib::jspell;
fn main() { asserteq!(jspell::spellnumber(5), "five"); asserteq!(jspell::spellnumber(11), "eleven"); asserteq!(jspell::spellnumber(101), "one hundred and one"); asserteq!(jspell::spellnumber(999), "nine hundred and ninety-nine"); } ```
```rust use jabba_lib::jtime;
fn main() { let wait = 1.5;
println!("Waiting for {:.2} seconds...", wait);
jtime::sleep(wait);
println!("Done.");
} ```
See the folder examples/ for more examples.