Git Product home page Git Product logo

is-rust's Introduction

ci-badge docs-badge

is-rust

Have you ever wanted to know if a value is rust, or at least rusty?

Maybe you're doing form validation for a Rust position at your company, and you want to make sure that someone only inputs Rust-acceptable values. Say that your form looks like this:

1: "What is your favourite programming language?"

<answer>

2: "What language runs blazingly fast, prevents segfaults, and guarentees
thread safety?"

<answer>

3: "What is your favourite colour defined in RGB?"

<answer>

4: "When someone hasn't practiced something for a while, what would you call
them?"

<answer>

Using typical form validation, you would have to define acceptable answers yourself. Using this library, you can simply use the function is_rust or is_at_least_rusty for all inputs.

Examples

For example, rust is rust:

extern crate is_rust;

assert!(is_rust::is_rust("rust")); // this is rust

Similarly, Rust is rust:

extern crate is_rust;

assert!(is_rust::is_rust("Rust")); // this is rust

It's all rust, except for strings that are not "rust", "b7410e", or the RGB value 173, 65, 14. Other than that, it's Rust. You can confirm this due to the fact that Python is not Rust:

extern crate is_rust;

assert!(!is_rust::is_rust("python")); // python is obviously not rust

Additionally you can check that something is rusty:

extern crate is_rust;

assert!(is_rust::is_rusty("rusty"));

Something can be at least rusty, or rust itself:

extern crate is_rust;

assert!(is_rust::is_at_least_rusty("rusty"));
assert!(is_rust::is_at_least_rusty("rust"));

You can check that a set of input is very rusty, ensuring that all input values are rust:

extern crate is_rust;

assert!(is_rust::is_very_rusty(&["rust", "Rust", "RUST", "b7410e"]));

Lastly, you can check that something is not rust, because booleans are hard:

extern crate is_rust;

assert!(is_rust::is_not_rust("Python"));

At this point, Rust should no longer sound like a word.

no_std

This crate supports no_std use cases, but without some string checks (such as not lowercasing strings).

To enable no_std support, explicitly disable the std feature in your Cargo.toml:

[dependencies.is-rust]
default-features = false
features = []
version = "~0.1"

Installation

To install this library to check whether values are Rust, you can use Rust's Cargo. Add the following to your Rust project's Cargo.toml:

[dependencies]
is-rust = "https://github.com/zeyla/is-rust"

License

ISC.

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.