Git Product home page Git Product logo

fn_block's Introduction

Build Status AppVeyor Status Crates.io Version

fn_block Crate

Library defining macros for calling blocks or expressions in a closure.

Quick Introduction

This library was mostly written to allow "safe navigation" with the ?. operator combination (seemingly) without jumping out of the current function. This allows a similar use of the operator as in other languages (such as Swift, C# or Kotlin).

To use this library, you have to add it to the dependencies of your Cargo.toml file

[dependencies]
fn_block = "0.2.1"

Then add the following lines to your module:

#[macro_use]
extern crate fn_block;
use fn_block::*;

Instead of the wildcard, you can also just import the symbols you need.

Here is an example on how to use the crate:

let o = Some("Foobar");
let s = fn_expr!{ o?.get(0..3)?.to_lowercase().into_some() };
assert_eq!("foo", s.unwrap());

Please visit the API Documentation for more details.

Functionality Overview

In short, this crate provides the following APIs:

  • The fn_expr macro allows wrapping an expression into a lambda that is directly called.
  • The IntoSome trait, which is implemented for all Sized types, allows to call into_some on a value to move it into an Option::Some.
  • The IntoOk trait, which is implemented for all Sized types, allows to call into_ok on a value to move it into an Result::Ok.

For more examples, please have a look at the test module.

Unstable Features

To use unstable features, the dependency declaration in your Cargo.toml has to be updated:

[dependencies]
fn_block = { version = "0.2.1", features = ["unproven"] }

Note that this crate's unstable features do work on stable Rust.

The following unstable APIs are available:

  • The fn_try macro allows wrapping an expression into a lambda, being called directly and recover from errors directly afterwards.

License

The fn_block crate is licensed under the following licenses:

Choose under which you want to use the library.

fn_block's People

Contributors

boereck avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.